哨兵循环错误的作业分配
Homework assignment with error with sentinel loops
好的,所以我正在做这个 class 作业,我必须编写一个程序,使用标记值控制循环来输入学生分数并显示学生人数和所有分数的平均值输入 -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: 错误: class 预期
studentCount = int.next();
C:\Users\sjccuser\Documents\NetBeansProjects\StudentsScoreReport\src\studentsscorereport\StudentsScoreReport.java:40: 错误: ';'预期的
studentCount = int.next();
6 个错误
我该如何修复这个 LOL?请帮助我,我的 class 太落后了,因为我没能完成这个项目。下面是我的全部代码。
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);
}
}// public 结束 static void main(String[] args);
} // public class StudentsScoreReport 结束;在此处输入代码
我能问一下这是什么语言吗?我可以看到多个语法错误,但我只想先 IDE 把它写出来。
好的,所以我正在做这个 class 作业,我必须编写一个程序,使用标记值控制循环来输入学生分数并显示学生人数和所有分数的平均值输入 -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: 错误: class 预期
studentCount = int.next();
C:\Users\sjccuser\Documents\NetBeansProjects\StudentsScoreReport\src\studentsscorereport\StudentsScoreReport.java:40: 错误: ';'预期的
studentCount = int.next();
6 个错误
我该如何修复这个 LOL?请帮助我,我的 class 太落后了,因为我没能完成这个项目。下面是我的全部代码。
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);
}
}// public 结束 static void main(String[] args); } // public class StudentsScoreReport 结束;在此处输入代码
我能问一下这是什么语言吗?我可以看到多个语法错误,但我只想先 IDE 把它写出来。