我正在試圖找到我的程序的模式,用戶輸入的數量從0-100到儘可能多的數量,我試圖找到模式這些數字,但每次我試圖找到它給我回3模式,我發現了一切,我只需要模式的幫助。如何使用Java找到數組的模式
import java.util.Scanner;
public class deveation {
public static void main(String Args[]) {
Scanner kbReader = new Scanner(System.in);
int sum = 0;
int bob[] = new int[101];
int total = 0;
int a = 0;
int min = 0;
int max = 100;
int mode = 0;
boolean stay_in_loop = true;
while (stay_in_loop) {
System.out.println("Please enter interger(s) from 0-100: ");
int number = kbReader.nextInt();
if (number < 0) {
stay_in_loop = false;
}
else {
total++;
bob[number]++;
}
}
int median = total/2 + 1;
while (median > 0) {
median -= bob[a];
a++;
}
a--;
boolean findit = true;
while (findit) {
if (bob[min] != 0)
findit = false;
else
min++;
}
boolean findme = true;
while (findme) {
if (bob[max] != 0)
findme = false;
else
max--;
}
for (int p = 0; p < 101; p++) {
if (bob[p] > mode) {
mode = bob[p];
}
for (int j = 0; j < 101; j++)
if (bob[j] <= mode)
//I don't know why I'm getting three for this
{
}
}
for (int i = 0; i < 101; i++) {
sum += bob[i] * i;
}
System.out.println(sum);
System.out.println(sum /= total);
System.out.println(a);
System.out.println(min);
System.out.println(max);
System.out.println(mode);
//You should start putting down these comments
}
}
無法重現您的問題。你的意思是你總是得到三個? – Aify 2015-04-01 17:20:10
在同一天有兩個答案,但你沒有投票,接受或答覆 - 如此低估。由於評論者說他們無法複製,投票也要關閉。 – halfer 2016-01-23 13:56:54