Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class lab3 {
- public static void main(String[] args) {
- int[] array;
- array = new int [4];
- for(int x = 0; x < 4; x++)
- {
- array[x]=(int)(1+Math.random()*20);
- } //--> end of for loop: for(int x = 0; x < 4; x++)
- for(int a = 0; a < array.length; a++)
- {
- System.out.println(array[a]);
- } //--> end of print for loop: for(int a = 0; a < array.length; a++)
- System.out.println("Duplicates in the array? True or False?");
- System.out.println(valueDuplicated(array));
- } //--> end of main method
- public static boolean valueDuplicated(int [] dupArray)
- {
- for(int i = 0; i < dupArray.length; i++){
- for(int x = i+1; x < dupArray.length; x++){
- if(dupArray[i] == dupArray[x]){
- return true;
- } //--> end of if statement for duplicate number check
- } //--> end of second for loop: for(int x = i+1; x < dupArray.length; x++)
- } // --> end of the first for loop: for(int i = 0; i < dupArray.length; i++)
- return false;
- } //--> end of duplicate method
- } //--> end of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement