/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner (System.in);
System.out.println("输入学生成绩:");
int a = in.nextInt();
char x;
if(a>80)
{
x=优;
}else if(a>70){
x=良;
}else if(a>60){
x=中;
}else{
x=差;
}
System.out.println("该学生成绩为:"+x);
输出只有“”内的汉字,无法输出x存储下的汉字。
优良中差几个字加上单引号''
你这个x是char类型,赋值汉子时,需要加单引号‘’
正确代码如下:
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
System.out.println("输入学生成绩:");
int a = in.nextInt();
char x;
if (a > 80) {
x = '优';
} else if (a > 70) {
x = '良';
} else if (a > 60) {
x = '中';
} else {
x = '差';
}
System.out.println("该学生成绩为:" + x);
}
测试结果如下:
若有帮助,还请题主采纳!感谢!!!