class FunctionDemo4
{
public static void main(String[] args)
{
getGrade(96);
System.out.println(y);
}
public static char getGrade(int x)
{
char y;
if (x>=90 && x<=100)
y='A';
else if (x >=80 && x <=89)
y='B';
else if (x>=70 && x>=79)
y='C';
else if (x>=60 && x<=69)
y='D';
else
y='E';
return y;
}
}输出错误,怎么 写?
{
public static void main(String[] args)
{
getGrade(96);
System.out.println(y);
}
public static char getGrade(int x)
{
char y;
if (x>=90 && x<=100)
y='A';
else if (x >=80 && x <=89)
y='B';
else if (x>=70 && x>=79)
y='C';
else if (x>=60 && x<=69)
y='D';
else
y='E';
return y;
}
}输出错误,怎么 写?
if(x<0 || x> 100){
return **;
}
**随便写个字母,之后接收返回值判断就行了要是不想返回字母,就改下返回值类型吧
可以了
{
public static void main(String[] args)
{
String returnStr = getGrade(96);
System.out.println(returnStr);
}
public static String getGrade(int x)
{
String y = "input error";if(x < 0 || x > 100){
return y;
}
if (x>=90 && x<=100)
y="A";
else if (x >=80 && x <=89)
y="B";
else if (x>=70 && x>=79)
y="C";
else if (x>=60 && x<=69)
y="D";
else
y="E";return y;
}
}