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;
}
}输出错误,怎么 写?

解决方案 »

  1.   

    你可以在public static char getGrade(int x){之后加上
    if(x<0 || x> 100){
    return **;
    }
    **随便写个字母,之后接收返回值判断就行了要是不想返回字母,就改下返回值类型吧
      

  2.   

    刚解决了,没有定义类型,加char y = getGrad(96);
    可以了
      

  3.   

    class  FunctionDemo4
    {
    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;
    }
    }
      

  4.   

       main()方法里改成  System.out.println(getGrade(96));