这个程序说第一个有效是无效的,无论如何,然后第二个输入无论如何都是有效的。知道为什么吗?
public class test
{
public static void main (String [] args)
{
int gradeValidity, verifiedGrade, grade, validGrade;
grade=gradeValidity ();
System.out.println("your total grade is"+grade);
System.exit(0);
}
private static int gradeValidity ()
{
int gradeOne;
boolean verifiedGrade ;
gradeOne=ConsoleInput.readInt("Input student grade");
verifiedGrade=((gradeOne>=0) && (gradeOne<=100));
do
{
System.out.println("Invalid input");
gradeOne=ConsoleInput.readInt("Input student grade");
}
while (!verifiedGrade);
return gradeOne;
}
}
将其更新为此。但现在我可以无与伦比(布尔和整数)
import io.*;
public class test
{
public static void main (String [] args)
{
int gradeValidity, verifiedGrade, grade, validGrade;
grade=gradeValidity ();
System.out.println("your total grade is"+grade);
System.exit(0);
}
private static int gradeValidity ()
{
int gradeOne;
boolean verifiedGrade ;
gradeOne=ConsoleInput.readInt("Input student grade");
verifiedGrade=((gradeOne>=0) && (gradeOne<=100));
while (gradeOne!=verifiedGrade);
{
System.out.println("Invalid input");
gradeOne=ConsoleInput.readInt("Input student grade");
}
return gradeOne;
}
}
它仍然会出现错误,第一个输入始终为假,第二个输入始终为真,无论 >0 和 <100
import io.*;
public class test
{
public static void main (String [] args)
{
int gradeValidity, verifiedGrade, grade, validGrade;
grade=gradeValidity ();
System.out.println("your total grade is"+grade);
System.exit(0);
}
private static int gradeValidity ()
{
int gradeOne;
boolean verifiedGrade;
gradeOne=ConsoleInput.readInt("Input student grade");
verifiedGrade=((gradeOne>=0) && (gradeOne<=100));
while (!verifiedGrade);
{
System.out.println("Invalid input");
gradeOne=ConsoleInput.readInt("Input student grade");
verifiedGrade=((gradeOne>=0) && (gradeOne<=100));
}
return gradeOne;
}
}