java 带百分比的方程式
java equation with percentages
我正在尝试创建一个程序来输出用户需要的成绩,以便在询问某些数据时在 class 中获得成绩。本质上是期末考试计算器。它要求用户输入他们当前的成绩、想要的成绩和考试的权重。我知道以前有人做过,但我的学期项目需要这个,我不想复制别人的作品。
public static void main(String[] args) {
Scanner in =new Scanner(System.in);
double g,r,w,f;
System.out.println("Enter your current class grade *Ex. 98* : ");
g = in.nextInt();
System.out.println("Enter your required class grade *Same format*: ");
r = in.nextInt();
System.out.println("Enter the weight of your Final Exam *Same format*: ");
w = in.nextInt();
f = (r - (100 - w) * g)/w;
System.out.println("The grade you need on your final exam is: " + f +"%");
}
我知道方程式有效,因为我用计算器测试过它,但我需要输出为百分比。 g、r 和 w 也需要是百分比,但我不知道如何编写一个与用户输入的百分比一起使用的方程式。
当我 运行 g=75, r=80, w=40 的程序时,它输出 75.875% 而答案应该是 87.5%。
根据您提供的数字,我假设您将 w 的值错误地输入为“4-”而不是 40
你的算法不正确。
正确的等式是:
f = (100 * r - (100 - w) * g)/w;
我正在尝试创建一个程序来输出用户需要的成绩,以便在询问某些数据时在 class 中获得成绩。本质上是期末考试计算器。它要求用户输入他们当前的成绩、想要的成绩和考试的权重。我知道以前有人做过,但我的学期项目需要这个,我不想复制别人的作品。
public static void main(String[] args) {
Scanner in =new Scanner(System.in);
double g,r,w,f;
System.out.println("Enter your current class grade *Ex. 98* : ");
g = in.nextInt();
System.out.println("Enter your required class grade *Same format*: ");
r = in.nextInt();
System.out.println("Enter the weight of your Final Exam *Same format*: ");
w = in.nextInt();
f = (r - (100 - w) * g)/w;
System.out.println("The grade you need on your final exam is: " + f +"%");
}
我知道方程式有效,因为我用计算器测试过它,但我需要输出为百分比。 g、r 和 w 也需要是百分比,但我不知道如何编写一个与用户输入的百分比一起使用的方程式。
当我 运行 g=75, r=80, w=40 的程序时,它输出 75.875% 而答案应该是 87.5%。
根据您提供的数字,我假设您将 w 的值错误地输入为“4-”而不是 40
你的算法不正确。
正确的等式是:
f = (100 * r - (100 - w) * g)/w;