Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Second.Semester;
- public class commonNumberInArray {
- public static void main(String[] args) {
- int[] number = {2,3,4,4,1,5,4,7,8,9,4,4};
- int counter = 0;
- int commonNum = 0;
- for (int i = 0; i <number.length ; i++) {
- int curr = 0;
- for (int j = 0; j <number.length ; j++) {
- if (number[i] == number[j]){
- curr++;
- }
- if (curr > counter){
- counter = curr;
- commonNum = number[i];
- }
- }
- }
- System.out.print("Number " + commonNum);
- System.out.println(" is repeated "+ counter + " times.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement