【发布时间】:2013-12-17 08:47:06
【问题描述】:
我正在尝试制作一个系统,其中有人输入 0-100 之间的数字,然后程序会将数字分配到设定的边界,基本上是一个成绩存储系统。 我将向您展示我的代码,然后详细说明。
public static void main(String[] args) {
//Boundary0/30/40/70 indicates which band the counter is for. e.g. 0-29, 30-39 etc
int Boundary0 = 0;
int Boundary30 = 0;
int Boundary40 = 0;
int Boundary70 = 0;
int Grade;
int count;
count = 0;
Scanner in = new Scanner(System.in);
//Read in first number
System.out.print("Enter an Integer");
Grade = in.nextInt();
while (Grade < 100){
//To count number of students
count++;
//To allocate each grade to corresponding tier
if(Grade >= 0 && Grade <= 29){
Boundary0++;
}
if(Grade >= 30 && Grade <= 39){
Boundary30++;
}
if(Grade >= 40 && Grade <= 69){
Boundary40++;
}
if(Grade >= 70 && Grade <= 100){
Boundary70++;
}
Grade = in.nextInt();
}
//To print each boundary seperately with the number of marks in each tier and overall total
System.out.println("0-29:" + " " + Boundary0 );
System.out.println("30-39:" + " " + Boundary30);
System.out.println("40-69:" + " "+ Boundary40);
System.out.println("70-100:" + " " +Boundary70);
System.out.println("Amount of Students: " + count);
}
}
当用户输入一个数字时,程序会将相应的边界变量加1
然后当用户输入大于 100 的数字时,程序停止并打印
层和每一层旁边,告诉用户每一层有多少值。
那么我想做的是,在代码末尾,sout 命令所在的位置
我不想从字面上说每个部分有多少个数字,我想代表
以 *s 为例
0-29: *****
30-39: ****
40-69: ********
70-100: *****
对不起,如果我没有完全清楚,我认为这可能只是对自己缺乏了解......
谢谢
【问题讨论】:
-
*是什么意思? -
那么如果30-39有2个数字,值是多少?
-
从字面上看,属于该类别的每个值只有一个 *,所以假设为一个层输入了 5 个值,我想要该类别的 5 颗星
-
如果 30-30 中有两个数字 Boundary30 等于 2,我希望在 30-39 之前打印两颗星:最后
-
问题是什么?你写的代码有什么问题?