To print unique numbers eliminating duplicates from given array

Write a java code to print only unique numbers by eliminating duplicate numbers from the array? (using collection framework)

Showing Answers 1 - 1 of 1 Answers

import javax.swing.JOptionPane;

public static void main(String[] args) {
int[] array = new int[10];
for (int i=0; i array[i] = Integer.parseInt(JOptionPane.showInputDialog("Please enter"
+ "an integer:"));
}
checkDuplicate (array);
}
public static void checkDuplicate(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;
}
if (!found)
System.out.println(array[i]);
}
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions