Guest User

Untitled

a guest
Jan 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import java.util.*;
  2. public class Duplicate{
  3. public static boolean readDataAndDuplicate(int[] x){
  4. Scanner input = new Scanner(System.in);
  5. int i;
  6. System.out.print("Enter from 1 up to " + x.length + " integers; ");
  7. System.out.println("end with -999");
  8. for (i = 0; i < x.length; i++){
  9. System.out.print("Enter next integer value: ");
  10. x[i] = input.nextInt();
  11. if (x[i] == -999) break;
  12. }
  13. if (i == 0){
  14. System.out.println("Error: you must enter at least 1 element");
  15. System.exit(0);
  16. }
  17.  
  18.  
  19. boolean duplicates=false;
  20. for (int j=0;j<x.length;j++)
  21. for (int k=0;k<x.length;k++)
  22. if (x[k]==x[j]){
  23. duplicates=true;
  24. }
  25. return false;
  26. public static void main(String[] args){
  27. readDataAndDuplicate()
  28. }
  29. }
  30. }
Add Comment
Please, Sign In to add comment