Vankata17

TheMostRepeatedNumberInArray

Mar 4th, 2021
1,031
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×