Java Outer and Inner loop example
Program to find or print first repeated/duplicate element
- public class Array {
- public static void main(String[] args) {
- int[] arr={1,2,3,4,5,0,0,1,3};
- Outer:for(int i=0;i<arr.length;i++){
- Innter: for(int j=i+1;j<arr.length;j++){
- if(arr[i]==arr[j]){
- System.out.println(arr[i]);
- break Outer;
- }
- }
- }
- /*String s="ffaghglklklh";
- Outer:for(int i=0;i<s.length();i++){
- Inner: for(int j=i+1;j<s.length();j++){
- if(s.charAt(i)==s.charAt(j)){
- System.out.println(s.charAt(i));
- break Outer;
- }
- }
- }*/
- }
- }
Comments
Post a Comment