import java.io.*;
class jex4_1
{
public static void main(String[] args )throws IOException
{
char a;
char b;
System.out.println("请输入你的成绩");
a=(char)System.in.read();
b=(char)System.in.read();
int score;
score=(a-'0')*10+b-'0';//score=a*10+b;
if(score>60)
System.out.println("你可以毕业了");
else
System.out.println("你不能毕业");
}
}
score=(a-'0')*10+b-'0';//score=a*10+b;
两都有什么不同?
class jex4_1
{
public static void main(String[] args )throws IOException
{
char a;
char b;
System.out.println("请输入你的成绩");
a=(char)System.in.read();
b=(char)System.in.read();
int score;
score=(a-'0')*10+b-'0';//score=a*10+b;
if(score>60)
System.out.println("你可以毕业了");
else
System.out.println("你不能毕业");
}
}
score=(a-'0')*10+b-'0';//score=a*10+b;
两都有什么不同?
两都有什么不同?
把a和b要转型
所以如果输入的是12,那么:
score=a*10+b; //score的值就是49*10+50=540;
而score=(a-'0')*10+b-'0';//score的值就是1*10+2=12;
int i = sc.nextInt();
a,b是字符不是数字,在和数字作计算时是使用的其ascii码。