Write a Java program to print mode values from a given a sequence of integers
- برمجة جافا
- برمجة
- 2021-05-01
- razanmazen8711884270
الأجوبة
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int cnt[] = new int[100];
int i;
System.out.println("How many integers would you like to input(Max.100?)");
int x = input.nextInt();
System.out.println("Input the integers:");
for (i = 0; i <x; i++){
int n = input.nextInt();
cnt[--n]++;
}
int max = 0;
for (int n : cnt){
if (max < n){
max = n;
}
}
System.out.println("Mode value(s)in ascending order:");
for (i = 0; i < cnt.length; i++){
if (cnt[i] == max){
System.out.println(i + 1);
}
}
}
}
Sample Output:
How many integers would you like to input(Max.100?) 5 Input the integers: 25 35 15 5 45 Mode value(s)in ascending order: 5 15 25 35 45
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال