这是我自己编写的代码:class Function1Demo
{
public static void main(String[] args)
{
int num = 102;
int x = num;
if(num > 100 || num < 0)
System.out.println("该分数错误");
else if(x < 60)
System.out.println('E');
else if(x >=60 && x <= 69)
System.out.println('D');
else if(x >= 70 && x <=79)
System.out.println('C');
else if(x >=80 && x <= 89)
System.out.println('B');
else if(x >= 90 && x <= 100)
System.out.println('A');
}
}
然后这是在函数学习时看到的笔记代码:
public static char getLevel(int num)
{
char level;
if(num >= 90 && num <= 100)
level = 'A';
else if(num >= 80 && num <= 89)
level = 'B';
else if(num >= 70 && num <= 79)
level = 'C';
else if(num >= 60 && num <= 69)
level = 'D';
else
level = 'E';
return level;
}
这两者到底有什么区别,请大神详细指教下 |
|