OneCompiler

find the duplicate number in array

152
import java.util.*;

public class Main {
    public static void main(String[] args) {
      Scanner input=new Scanner(System.in);
      int a[]={1,2,2,3,3,4,4};
      for(int i=0;i<a.length-1;i++){
        if(a[i]==a[i+1]){
          System.out.print(a[i]+" ");
        }
      }
    }
}