Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package AssignmentOne;
- import java.util.*;
- public class Unique {
- public static void main(String[] args) {
- getNumbers();
- }
- public static void getNumbers() {
- int[] nums = new int[5];
- Scanner kb = new Scanner(System.in);
- int index = 0;
- while(index<5) {
- System.out.print("Please enter a number: ");
- int num = kb.nextInt();
- nums[index] = num;
- findUnique(nums);
- index++;
- }
- kb.close();
- }
- public static void findUnique(int[] num) {
- int number =0;
- for(int i=0;i<num.length;i++) {
- boolean isDuplicate= false;
- for(int j=0;j<i;j++) {
- if(num[i]==num[j]) {
- isDuplicate = true;
- break;
- }
- }
- if(!isDuplicate) {
- System.out.println(num[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment