Advertisement
Vankata17

TheMostRepeatedNumberInArray

Mar 4th, 2021
1,302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. package Second.Semester;
  2.  
  3. public class commonNumberInArray {
  4.     public static void main(String[] args) {
  5.         int[] number = {2,3,4,4,1,5,4,7,8,9,4,4};
  6.         int counter = 0;
  7.         int commonNum = 0;
  8.         for (int i = 0; i <number.length ; i++) {
  9.             int curr = 0;
  10.             for (int j = 0; j <number.length ; j++) {
  11.                 if (number[i] == number[j]){
  12.                     curr++;
  13.                 }
  14.                 if (curr > counter){
  15.                     counter = curr;
  16.                     commonNum = number[i];
  17.                 }
  18.             }
  19.         }
  20.         System.out.print("Number " + commonNum);
  21.         System.out.println(" is repeated "+ counter + " times.");
  22.     }
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement