Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class R727 {
- public static void main(String[] args) {
- int[] values = {1, 2, 3, 4, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8};
- int popular = values[0];
- int popularCount = 0;
- int tempCount = 0;
- for(int i = 0; i < values.length; i++) {
- tempCount = 1;
- for(int j = i + 1; j < values.length; j++) {
- if(values[j] == values[i]) {
- tempCount++;
- }
- }
- if(tempCount > popularCount) {
- popular = values[i];
- popularCount = tempCount;
- }
- }
- System.out.println("The number " + popular + " appears " + popularCount + " times.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement