Advertisement
Camer047

problem3

May 23rd, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. public void problem3() {
  2.  
  3. System.out.println("Enter Digits:");
  4. Scanner scanIn = new Scanner(System.in);
  5. int index = 0;
  6.  
  7.  
  8. while (scanIn.hasNextLine()) {
  9. String in = scanIn.nextLine();
  10. String[] split = in.split(" ");
  11. int occurences = 0, mode = 0, last = 0;
  12. index++;
  13.  
  14. for (String s : split) {
  15. int i = Integer.parseInt(s);
  16. occurences = 0;
  17. for (int n = 0; n < split.length; n++) {
  18. //if s is in n
  19. if (Integer.parseInt(split[n]) == i) {
  20. occurences++;
  21. }
  22.  
  23. }
  24. if (occurences > last) {
  25. last = occurences;
  26. mode = i;
  27. }
  28. }
  29. System.out.println();
  30. System.out.println("Case " + index + ": " + mode + " Appears " + last + " times.");
  31. }
  32.  
  33. }
  34.  
  35. ###INPUT###
  36. 10
  37. 10 10
  38. 10 10 10
  39. 10 2 10
  40. 10 100000 10
  41. 2 100000 2 10
  42. 2 2 2 3
  43. 10 2 3 3
  44. 10 10 10 10
  45. 10 10 10 2 2
  46. 2 2 2 10 2
  47. 2 2 2 2 2
  48. 4 2 3 20 20 5
  49. 10 3 10 5 5 7 0 -10 10
  50. 10 2 3 4 5 6 7 8 8
  51. 10 2 3 4 4 5 5 7 7 7
  52. 10 2 3 3 4 4 5 5 6 6 7 7 7
  53. 10 10 10 2 2 3 3 4 4 4 5 5 6 6 7 7
  54. 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