So my code asks a user to enter 10 numbers, it then checks to see if the number is already in the array, then prints out the entered numbers in a dialog box, but does not print duplicates (i.e. if the entered numbers are 1,2,3,4,5,6,7,8,9,9- the program prints 1,2,3,4,5,6,7,8,9. Excluding extra 9).
I got it mostly working and it works fine if i try to print it in the console, but it is the dialog box that is throwing me off, as it includes the duplicate numbers.
heres the code:
public static void main(String[] args) { int[] array = new int[10]; for (int i=0; i<array.length;i++) { array[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter an integer:")); }//end of for checkArray (array); JOptionPane.showMessageDialog(null, array[0] + " " + array[1] + " " + array[2] + " " + array[3] + " " + array[4] + " " + array[5] + " " + array[6] + " " + array[7] + " " + array[8] + " " + array[9]); }//end of main public static int checkArray(int array []) { for (int i = 0; i < array.length; i++) { boolean found = false; for (int j = 0; j < i; j++) if (array[i] == array[j]) { found = true; break; }//end of if if (!found) return array[i]; //JOptionPane.showMessageDialog(null, array[0] + " " + array[1] + " " + array[2] + " " + array[3] + " " + array[4] + " " + array[5] + " " + array[6] + " " + array[7] + " " + array[8] + " " + array[9]); }//end of for return 1; }//end of checkArray }//end of class
This is where i was just going into console when it works just fine.
if (!found) System.out.println(array[i]);