Java Outer and Inner loop example

Program to find or print first repeated/duplicate element



  1. public class Array {

  2. public static void main(String[] args) {
  3. int[] arr={1,2,3,4,5,0,0,1,3};
  4. Outer:for(int i=0;i<arr.length;i++){
  5. Innter: for(int j=i+1;j<arr.length;j++){
  6. if(arr[i]==arr[j]){
  7. System.out.println(arr[i]);
  8. break Outer;
  9. }
  10. }
  11. }
  12. /*String s="ffaghglklklh";
  13. Outer:for(int i=0;i<s.length();i++){
  14. Inner: for(int j=i+1;j<s.length();j++){
  15. if(s.charAt(i)==s.charAt(j)){
  16. System.out.println(s.charAt(i));
  17. break Outer;
  18. }
  19. }
  20. }*/
  21. }

  22. }


Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation