gpt4 book ai didi

java - 简单的平均误差,找不到正确的代码

转载 作者:行者123 更新时间:2023-12-01 13:27:24 26 4
gpt4 key购买 nike

我终于编写了我的程序(因为我是初学者,所以花了一段时间),该程序的作用是:

  • 打印带有 2 个选项的菜单:平均成绩或退出。

  • 如果用户选择平均成绩,它会询问他们的姓名。然后它告诉他们成绩的平均顺序。

  • 然后他们输入任意数量的成绩,然后按 -1,它会给出这些成绩的总和以及平均值。对于家庭作业、测验和测试,它会执行 3 次。

我需要做的最后一件事是平均所有 3 个成绩,然后输出:

  • System.out.println( name, "平均值为 ", +averageFinal );

我的作业中给出了这一行:

Final Average = 0.25*HomeworkAvg + 0.25*QuizAvg + 0.50*TestAvg = 77.87

我试图将其放入程序中:

averageFinal = 0.25*averageOne + 0.25*averageTwo + 0.50*averageThree;

但由于某种原因,我遇到了这个奇怪的编译错误,我似乎无法修复:

Assignment3.java:120: error: cannot find symbol
System.println( name, "'s final average is ", averageFinal );
^
symbol: method println(String,String,double)
location: class System
1 error

我的代码是否存在一个简单的问题,或者我是否必须更改字符串方法中的某些内容?

import java.util.Scanner;

public class Assignment3 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

int choice;
int total;
double averageOne;
double averageTwo;
double averageThree;
double averageFinal;
int grade;

int gradeCounterone;
int gradeCountertwo;
int gradeCounterthree;

gradeCounterone = 0;
gradeCountertwo = 0;
gradeCounterthree = 0;
total = 0;

String name;

System.out.println("Enter 1 or 2: \n 1 - Average grades \n 2 - Quit");
choice = input.nextInt();

if (choice == 1) {
System.out.println("Enter the students name:");
name = input.next();

System.out.println("Grades will be entered in this order: \n 1) Homework Grades \n 2) Quiz Grades \n 3) Test Grades ");

{
System.out.println("Enter homework grades, press -1 when finished:");
grade = input.nextInt();

while (grade != -1) {
total = total + grade;
gradeCounterone = gradeCounterone + 1;

System.out.println("Enter homework grades, press -1 when finished:");
grade = input.nextInt();

}
if (gradeCounterone != 0) {
averageOne = (double) total / gradeCounterone;

System.out.printf("\nThe total of the %d homework grades is %d\n", gradeCounterone, total);
System.out.printf("\nThe average of the homework grades is %.2f\n ", averageOne);

}

// second loop for quiz grades

System.out.println("\nEnter quiz grades, press -1 when finished:");
grade = input.nextInt();

while (grade != -1) {
total = total + grade;
gradeCountertwo = gradeCountertwo + 1;

System.out.println("Enter quiz grades, press -1 when finished:");
grade = input.nextInt();

}
if (gradeCountertwo != 0) {

averageTwo = (double) total / gradeCountertwo;

System.out.printf("\nThe total of the %d quiz grades is %d\n", gradeCountertwo, total);
System.out.printf("\nThe average of the quiz grades is %.2f\n ", averageTwo);

}

// third loop for test grades

System.out.println("\nEnter test grades, press -1 when finished:");
grade = input.nextInt();

while (grade != -1) {
total = total + grade;
gradeCounterthree = gradeCounterthree + 1;

System.out.println("Enter test grades, press -1 when finished:");
grade = input.nextInt();

}
if (gradeCounterthree != 0) {

averageThree = (double) total / gradeCounterthree;

System.out.printf("\nThe total of the %d test grades is %d\n", gradeCounterthree, total);
System.out.printf("\nThe average of the test grades is %.2f\n ", averageThree);

}

averageFinal = 0.25 * averageOne + 0.25 * averageTwo + 0.50 * averageThree;
System.println(name, "'s final average is ", averageFinal);

}

} else if (choice == 2) {
System.out.println("Exiting program.");
} else {
System.out.println("Invalid response, exiting program.");
}
}
}

最佳答案

应该是:

System.out.println( name + " s final average is " + averageFinal );

而不是

System.println( name, "' s final average is ", averageFinal );

关于java - 简单的平均误差,找不到正确的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21744351/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com