GeekInterview.com
Series: Subject: Topic:
Question: 19 of 375

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)
Asked by: Interview Candidate | Asked on: Sep 23rd, 2011
Showing Answers 1 - 1 of 1 Answers
Sandhya.Kishan

Answered On : May 26th, 2012

View all answers by Sandhya.Kishan

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

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.