package studenttest;
import java.util.Scanner;
public class StudentTest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int total=0;
int gradeCounter=0;
int aCount=0;
int bCount=0;
int cCount=0;
int dCount=0;
int fCount=0;
System.out.printf("%s%n%s%n %s%n","Enter the integer grades in the range
0-100.","Type the end-of-file indicator to terminate input:","On
Unix/Linux/Mac OS X type <Ctrl> d then press Enter On Windows type <Ctrl>
z then press Enter");
while(input.hasNext()){
int grade = input.nextInt();
total += grade;
++gradeCounter;
switch(grade/10){
case 9:
case 10:
++aCount;
break;
case 8:
++bCount;
break;
case 7:
++cCount;
break;
case 6:
++dCount;
break;
default:
++fCount;
break;
}
}
System.out.println("Grade Report: ");
if(gradeCounter != 0){
double average = (double)total/gradeCounter;
System.out.printf("Total of the %d grades entered is %d%n",
gradeCounter,total);
System.out.printf("Class average is %f%n", average);
System.out.printf("%n%s%n%s%d%n%s%d%n%s%d%n%s%d%n%s%d%n","Number of
Students who received each grade:
","A",aCount,"B",bCount,"C",cCount,"D",dCount,"F",fCount);
}
else
System.out.println("No Grades were entered");
}
}
如何停止此循环? 我目前在Windows操作系统上,确切地说是Windows 10。我尝试使用Ctrl Z来关闭输入输入+输入的过程,但是没有工作。如果你想知道我正在使用NetBeans!