Created
April 16, 2015 19:41
-
-
Save jonathan-irvin/ef96c4480ae47c0077fe to your computer and use it in GitHub Desktop.
integer Occurences
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 Occurrences { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
System.out.println("How many numbers will you enter? "); | |
int entries = in.nextInt(); | |
int[] numbers = new int[entries]; | |
System.out.print("Enter data: "); | |
for(int i=0; i<numbers.length; i++){ | |
numbers[i] = in.nextInt(); | |
} | |
Arrays.sort(numbers); | |
for (int i=0; i<numbers.length;i++){ | |
int count = 1; | |
int number = numbers[i]; | |
while (i < (numbers.length - 1) && numbers[i+1] == number){ | |
count++; | |
i++; | |
} | |
System.out.print("There are "+count); | |
System.out.println(" "+numbers[i]+"s"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment