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”,或者当我尝试编辑任何东西时(变量位置,布尔运算符等)我正在使用的编译器冻结。我不知道这是否重要,但我在iPad上使用Pico Compiler应用程序来运行它。当我评论for循环时,按预期工作(毫不奇怪)。没有错误显示。
答案 0 :(得分:1)
这是一种使用@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";
}
你离开的地方还有另外一件事,但你提供的代码并不是你想要的。你应该谷歌java arrays
或咨询文字;这只是为了让你入门。希望它有所帮助而不会过于混乱。
(顺便说一下,这会使pointsGet
与numGrade
相同;如果您真的希望hourFourPointsGet
为100,则可能需要更改代码。)