Created
April 16, 2015 19:43
-
-
Save jonathan-irvin/e88e83fab4550c6f0423 to your computer and use it in GitHub Desktop.
Unique Ints
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.Scanner; | |
public class UniqueInts { | |
public static void main(String[] args) { | |
final int TOTAL_INTS = 10; | |
Scanner input = new Scanner(System.in); | |
int num[] = new int[TOTAL_INTS]; | |
for(int i=0;i<TOTAL_INTS;i++){ | |
System.out.print("Enter Number "+(i+1)+": "); | |
num[i] = input.nextInt(); | |
} | |
Arrays.sort(num); | |
int counter = num[0]; | |
int lastfound = 0; | |
for(int i=0;i<num.length;i++){ | |
while( (num[i] != counter) ){ | |
if(num[i]!=lastfound){ | |
counter++; | |
}else{break;} | |
} | |
if(num[i]==counter){ | |
System.out.println(num[i]); | |
lastfound = num[i]; | |
counter++; | |
continue; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment