gpt4 book ai didi

Java评分程序: For-Loop Freezing or Working Improperly Issue

转载 作者:行者123 更新时间:2023-12-01 11:02:02 25 4
gpt4 key购买 nike

if(numGrade[1] >= 100)
{
System.out.println("Your English grade is perfect! Keep it up!");
}

else if(numGrade[1] < 90 && numGrade[1] > 80)
{
for(;testGrade >= 90; testPossible[1]++, testGet[1]++)
{
if(testGet[1] == 0)
{
System.out.println("SYSTEM: Illegal division value for testGet[1]");
if(testPossible[1] == 0)
{
System.out.println("SYSTEM: Illegal division value for testPossible[1]");
System.out.println("SYSTEM: Exiting program...");
System.exit(0);
}
System.out.println("SYSTEM: Exiting program...");
System.exit(0);
}

else if(testPossible[1] == 0)
{
System.out.println("SYSTEM: Illegal division value for testPossible[1]");
System.out.println("SYSTEM: Exiting program...");
System.exit(0);
}

else
{
testGrade[1] = testGet[1]/testPossible[1];
}
}
testTheory[1] = pointsGet[1] - testGet[1];
System.out.println(testTheory[1] + " points needed to get an A in English!");
}

else if(numGrade[1] < 80 && numGrade[1] > 70)
{
for(;testGrade[1] >= 80; testPossible[1]++, testGet[1]++)
{
if(testGet[1] == 0)
{
System.out.println("SYSTEM: Illegal division value for testGet[1]");
if(testPossible[1] == 0)
{
System.out.println("SYSTEM: Illegal division value for testPossible[1]");
System.out.println("SYSTEM: Exiting program...");
System.exit(0);
}
System.out.println("SYSTEM: Exiting program...");
System.exit(0);
}

else if(testPossible[1] == 0)
{
System.out.println("SYSTEM: Illegal division value for testPossible[1]");
System.out.println("SYSTEM: Exiting program...");
System.exit(0);
}

else
{
testGrade[1] = testGet[1]/testPossible[1];
}
}
testTheory[1] = pointsGet[1] - testGet[1];
System.out.println(testTheory[1] + " points needed to get a B in English!");
}

else if(numGrade[1] < 70 && numGrade[1] > 60)
{
for(;testGrade[1] >= 70; testPossible[1]++, testGet[1]++)
{
if(testGet[1] == 0)
{
System.out.println("SYSTEM: Illegal division value for testGet[1]");
if(testPossible[1] == 0)
{
System.out.println("SYSTEM: Illegal division value for testPossible[1]");
System.out.println("SYSTEM: Exiting program...");
System.exit(0);
}
System.out.println("SYSTEM: Exiting program...");
System.exit(0);
}

else if(testPossible[1] == 0)
{
System.out.println("SYSTEM: Illegal division value for testPossible[1]");
System.out.println("SYSTEM: Exiting program...");
System.exit(0);
}

else
{
testGrade[1] = testGet[1]/testPossible[1];
}
}
testTheory[1] = pointsGet[1] - testGet[1];
System.out.println(testTheory[1] + " points needed to get a C in English!");
}

else if(numGrade[1] < 50)
{
for(;testGrade[1] >= 60; testPossible[1]++, testGet[1]++)
{
if(testGet[1] == 0)
{
System.out.println("SYSTEM: Illegal division value for testGet[1]");
if(testPossible[1] == 0)
{
System.out.println("SYSTEM: Illegal division value for testPossible[1]");
System.out.println("SYSTEM: Exiting program...");
System.exit(0);
}
System.out.println("SYSTEM: Exiting program...");
System.exit(0);
}

else if(testPossible[1] == 0)
{
System.out.println("SYSTEM: Illegal division value for testPossible[1]");
System.out.println("SYSTEM: Exiting program...");
System.exit(0);
}

else
{
testGrade[1] = testGet[1]/testPossible[1];
}
}
testTheory[1] = pointsGet[1] - testGet[1];
System.out.println(testTheory[1] + " points needed to get a D in English!");
}
else if(numGrade[1] < 0)
{
System.out.println("SYSTEM: Could not show numGrade[1]");
System.out.println("SYSTEM: Negative grade value for numGrade[1]");
}

else if(numGrade[1] == 0)
{
System.out.println("SYSTEM: Could not show numGrade[1]");
System.out.println("SYSTEM: No grade value for numGrade[1]");
}

else
{
System.out.println("SYSTEM: Could not show numGrade[1]");
System.out.println("SYSTEM: Unknown cause");
}
System.exit(0);

每当我尝试运行这个程序时,我要么得到“你需要 0 分才能获得 B”,要么当我尝试真正编辑任何内容(变量位置、 boolean 运算符等)时,我正在使用的编译器卡住。我不知道这是否重要,但我正在 iPad 上使用 Pico Compiler 应用程序来运行它。当我评论 for 循环时按预期工作(毫不奇怪)。没有显示任何错误。

最佳答案

这是一种使用 @RealSkeptic 提到的 array 概念(和 for 循环)开始减少代码大小的方法:

  double[] numGrade       = { 79,  75,  78, 100,  70,  78};
double[] pointsPossible ;
double[] pointsGet ;
String[] gpa;

for (int i = 0; i < numGrade.length; i++) {
pointsGet[i] = numGrade[i];
pointsPossible[i] = 100;
gpa[i] = "A";
}

你从那里去哪里是另一回事,但你提供的代码不是你想要的。您应该 Google java array 或查阅文本;这只是为了让您开始。希望它能有所帮助,但不会过于困惑。

(顺便说一句,这使得 pointsGetnumGrade 相同;如果您确实希望 hourFourPointsGet 成为100。)

关于Java评分程序: For-Loop Freezing or Working Improperly Issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33265532/

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