Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void problem3() {
- System.out.println("Enter Digits:");
- Scanner scanIn = new Scanner(System.in);
- int index = 0;
- while (scanIn.hasNextLine()) {
- String in = scanIn.nextLine();
- String[] split = in.split(" ");
- int occurences = 0, mode = 0, last = 0;
- index++;
- for (String s : split) {
- int i = Integer.parseInt(s);
- occurences = 0;
- for (int n = 0; n < split.length; n++) {
- //if s is in n
- if (Integer.parseInt(split[n]) == i) {
- occurences++;
- }
- }
- if (occurences > last) {
- last = occurences;
- mode = i;
- }
- }
- System.out.println();
- System.out.println("Case " + index + ": " + mode + " Appears " + last + " times.");
- }
- }
- ###INPUT###
- 10
- 10 10
- 10 10 10
- 10 2 10
- 10 100000 10
- 2 100000 2 10
- 2 2 2 3
- 10 2 3 3
- 10 10 10 10
- 10 10 10 2 2
- 2 2 2 10 2
- 2 2 2 2 2
- 4 2 3 20 20 5
- 10 3 10 5 5 7 0 -10 10
- 10 2 3 4 5 6 7 8 8
- 10 2 3 4 4 5 5 7 7 7
- 10 2 3 3 4 4 5 5 6 6 7 7 7
- 10 10 10 2 2 3 3 4 4 4 5 5 6 6 7 7
- 7 7 10 2 10 2 10 2 2 3 3 3 4 -10 2 5 <-- not reading this line
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement