Answers

Question and Answer:

  Home  Aptitude

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

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]);

}

}

 195 views

More Questions for you: