Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Zadacha2_2 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String input = sc.nextLine();
- String[] stringArray = input.split(" ");
- int[] intArray = new int[stringArray.length];
- for (int i = 0; i < stringArray.length; i++) {// string array to int array
- String numberAsString = stringArray[i];
- intArray[i] = Integer.parseInt(numberAsString);
- }
- int number=0;
- int count=0;
- int mostCommonNum=0;
- int mostCommonCount=0;
- for(int i=0; i<intArray.length;i++) {
- number=intArray[i];
- for(int j=0; j<intArray.length;j++) {
- if(number==intArray[j]) {
- count++;
- }
- }
- if(mostCommonNum<count) {
- mostCommonNum=intArray[i];
- mostCommonCount=count;
- }
- count=0;
- }
- System.out.println("The most common number is:"+mostCommonNum);
- System.out.println("It occurs " +mostCommonCount+" times" );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement