Guest User

Untitled

a guest
Feb 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. package com.sandbox.test01;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.  
  8. public static boolean checkArray(int [] x)
  9. {
  10. for(int i = 0; i < x.length; i++)
  11. {
  12. for(int j = 0; j < x.length; j++)
  13. {
  14. if(x[i] == x[j])
  15. {
  16. if(i != j) // make sure its not comparing the same value to itself :P
  17. return true;
  18. }
  19. }
  20. }
  21.  
  22. return false;
  23. }
  24.  
  25. public static void main(String args [])
  26. {
  27.  
  28. int x [] = { 0, 1, 2, 3, 4, 5, 5, 6, 7, 8 };
  29.  
  30. if(checkArray(x))
  31. System.out.println("Duplicate found!");
  32. else
  33. System.out.println("No Dupes");
  34.  
  35. return;
  36. }
  37. }
Add Comment
Please, Sign In to add comment