Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. public class lab3 {
  2.  
  3. public static void main(String[] args) {
  4.  
  5. int[] array;
  6. array = new int [4];
  7.  
  8. for(int x = 0; x < 4; x++)
  9. {
  10. array[x]=(int)(1+Math.random()*20);
  11. } //--> end of for loop: for(int x = 0; x < 4; x++)
  12.  
  13. for(int a = 0; a < array.length; a++)
  14. {
  15. System.out.println(array[a]);
  16. } //--> end of print for loop: for(int a = 0; a < array.length; a++)
  17.  
  18.  
  19. System.out.println("Duplicates in the array? True or False?");
  20.  
  21. System.out.println(valueDuplicated(array));
  22. } //--> end of main method
  23. public static boolean valueDuplicated(int [] dupArray)
  24. {
  25. for(int i = 0; i < dupArray.length; i++){
  26. for(int x = i+1; x < dupArray.length; x++){
  27. if(dupArray[i] == dupArray[x]){
  28. return true;
  29. } //--> end of if statement for duplicate number check
  30.  
  31. } //--> end of second for loop: for(int x = i+1; x < dupArray.length; x++)
  32. } // --> end of the first for loop: for(int i = 0; i < dupArray.length; i++)
  33. return false;
  34. } //--> end of duplicate method
  35. } //--> end of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement