微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

前哨循环出错的家庭作业分配

如何解决前哨循环出错的家庭作业分配

好,所以我正在做这个课堂作业,在这里我必须编写一个程序,该程序使用哨兵值控制的循环输入学生分数,并在输入-1时显示学生人数和所有分数的平均值。程序首次启动时将显示标题。有效的分数值是从0到100。输入的分数超过100时,该分数将不包括在总数中,并且学生人数也不应增加。输入值-1时,列表结束,程序显示输入的有效分数的数量和平均分数。如果输入-1作为第一个输入,则不会报告任何错误,并且会显示一条消息,提示没有输入分数。

现在,我本来能够获得该程序的输出,以便我可以输入成绩,但是我意识到,当我输入“ 999”或“ -1”时,程序没有停止,并且平均我从键盘输入的成绩,因此我一直在尝试对其进行修复,但现在我处于困境,对如何解决它一无所知。我是Java编程和NetBeans软件的初学者。老实说,由于我没有任何线索,我必须不断查找错误的含义。我真的可以得到一些帮助,因为我的教授上周不得不撤离他,他无法访问他的计算机,所以我一个人来。 我现在遇到的错误是: C:\ Users \ sjccuser \ Documents \ NetBeansprojects \ StudentsscoreReport \ src \ studentsscorereport \ StudentsscoreReport.java:38:错误:未封闭的字符文字 其他(studentCount =='999'); {
C:\ Users \ sjccuser \ Documents \ NetBeansprojects \ StudentsscoreReport \ src \ studentsscorereport \ StudentsscoreReport.java:38:错误:不是语句 其他(studentCount =='999'); {
C:\ Users \ sjccuser \ Documents \ NetBeansprojects \ StudentsscoreReport \ src \ studentsscorereport \ StudentsscoreReport.java:38:错误:“ else”不带“ if” 其他(studentCount =='999'); {
C:\ Users \ sjccuser \ Documents \ NetBeansprojects \ StudentsscoreReport \ src \ studentsscorereport \ StudentsscoreReport.java:38:错误:未封闭的字符文字 其他(studentCount =='999'); {
C:\ Users \ sjccuser \ Documents \ NetBeansprojects \ StudentsscoreReport \ src \ studentsscorereport \ StudentsscoreReport.java:40:错误:预期的类 studentCount = int.next(); C:\ Users \ sjccuser \ Documents \ NetBeansprojects \ StudentsscoreReport \ src \ studentsscorereport \ StudentsscoreReport.java:40:error:';'预期 studentCount = int.next(); 6个错误

我该如何修复这个哈哈?请帮助我,我的班上太落后了,因为我无法完成这个项目。下面是我的完整代码

public class StudentsscoreReport {

public static final int score_COUNT = 5;
     
public static void main(String[] args) {
// Define Constants
double studentCount= 0; //students inital grade
double totalscore = 0; // students grades combined
double averagescore;  // average score from the number of students
int scoreCount = 0;  // output score from the calculated average score
    
// create the Scanner object. 
Scanner stdin = new Scanner(system.in); 
 
// INPUT: Title at the top of the out   
System.out.println ("Kristina Rosado's Students score Report");
System.out.println ("Enter a students score,0 - 100,999 to quit");   //input score from keyboard

//  PROCESS: Read the scores for the first city 
//  NOTE: the program's score starts at 0,but people count from 1       
if (studentCount == 0 && totalscore == 0 ){
averagescore = (totalscore / studentCount);
} // users input -1 at the first time

else {
averagescore = totalscore / studentCount;
System.out.printf ("%d student scores were entered\n",studentCount);
System.out.printf ("\nThe average of score of %d students is %.2f",studentCount,averagescore);

else (studentCount == '999');{  
System.out.println ("Thank you for your entries");
studentCount = int.next();
}     
}
while (studentCount != -1){

if (studentCount < -1) {
System.out.print("Please try again");
System.out.printf ("Enter the score for the next student #%d: ",scoreCount+1); 
// input the next score 
studentCount = stdin.nextDouble();   
} else if (studentCount > 100) {
System.out.print("Please try again");
System.out.printf ("Enter the score for the next student #%d: ",scoreCount+1);
// input the next score
studentCount = stdin.nextDouble();
} // end of for loop
// end of for loop 
}          
System.out.println ("Illegal entry for score");{
System.out.println("There is no student score entered ");
averagescore = totalscore / scoreCount; 
System.out.printf("\nThe average score for %d students is %8.2f\n",scoreCount,averagescore);
}       

} //公共静态void main(String [] args);的结尾。 } //公共课程StudentsscoreReport结束;在此处输入代码

解决方法

我可以问一下这是什么语言吗?我可以看到多个语法错误,但我只想先将其放入IDE。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。