Aptitude Question:
Download Questions PDF

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

Answer:

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

Download Aptitude Interview Questions And Answers PDF

Previous QuestionNext Question
Three beauty pageant finalists-Cindy, Amy and Linda-The winner was musician. The one who was not last or first was a math major. The one who came in third had black hair. Linda had red hair. Amy had no musical abilities. Who was first?From 7:00 AM to 11:00 AM it rained 2.25 inches. At 11:00 AM the rain increased to fall at a rate of 1.25 in. every two hours. How many inches of rain landed on the ground by 5:00 PM?

a) 7
b) 9.75
c) 6
d) 3.25
e) 7.125