public class GetNum {
public static void main(String[] args) {
Scanner sr = new Scanner(System.in);
System.out.println("录入一个三位整数数");
int x = sr.nextInt();
int g = x % 10;
int s = x % 100 / 10;
int b = x / 100;
System.out.println("数字" + x + "的个位是" + g + ",十位是" + s + ",百位是" + b);
}
}
第三题:看程序说结果,请不要提前运行?
public class Test03 {
public static void main(String[] args) {
int x = 4;
int y = (--x)+(x--)+(x*10);
System.out.println("x = " + x + ",y = " + y);
}
}
结果:
x=2
y=26
第四题:看程序说结果,请不要提前运行?
public class Test04 {
public static void main(String[] args) {
int a = 10;
int b = 20;
int x = a + b++;
System.out.println("b=" + b);
System.out.println("x=" + x);
}
}
结果:
b=21
x=30
第五题:看程序说结果,请不要提前运行?
public class Test05 {
public static void main(String[] args) {
short s = 30;
int i = 50;
s += i;//s=80
System.out.println("s="+s);
int x = 0;
int y = 0;
int z = 0;
boolean a,b;
a = x>0 & y++>1;
System.out.println("a="+a);//a=false
System.out.println("y="+y);//y=1
b = x>0 && z++>1;
System.out.println("b="+b);//b=false
System.out.println("z="+z);//z=0
a = x>0 | y++>1;
System.out.println("a="+a);//a=false
System.out.println("y="+y);//y=2
b = x>0 || z++>1;
System.out.println("b="+b);//b=false
System.out.println("z="+z); //z=1
}
}
结果:
s=80
a=false
y=1
b=false
z=0
a=false
y=2
b=false
z=1
public class Score {
public static void main(String[] args) {
Scanner sr = new Scanner(System.in);
System.out.println("录入一个学生成绩");
int x = sr.nextInt();
System.out.println((x >= 60) ? "合格" : "不合格");
}
}
public class MinAndSum {
public static void main(String[] args) {
Scanner sr = new Scanner(System.in);
System.out.println("录入三个int类型的数字");
int x = sr.nextInt();
int y = sr.nextInt();
int z = sr.nextInt();
int min = (x < y ? x : y) < z ? (x < y ? x : y) : z;
int sum = x + y + z;
System.out.println("求出三个数中的最小值" + min);
System.out.println("求出三个数的和" + sum);