运算符:
下面的都是相关的练习:
1、键盘录入一个三位整数数,请分别获取该三位数上每一位的数值
import java.util.Scanner;
public class Test02 {
public static void main(String[] args) {
System.out.println("请输入一个三位整数:");
int value = new Scanner(System.in).nextInt();
int geWei = value % 10;
int shiWei = (value / 10) % 10;
int baiWei = value / 100;
System.out.println("数字" + value + "的个位是 " + geWei + ", 十位是 " + shiWei
+ ", 百位是 " + baiWei);
}
}
2、说出运行结果:
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); // y = 26; x = 2
}
}
public class Test05 {
public static void main(String[] args) {
short s = 30;
int i = 50;
s += i;
System.out.println("s="+s); // s = 80
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
}
}
3、键盘录入三个int类型的数字,1)求出三个数中的最小值并打印,2)求出三个数的和并打印
import java.util.Scanner;
public class Test07 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个整数:");
int num1 = sc.nextInt();
System.out.println("请输入第二个整数:");
int num2 = sc.nextInt();
System.out.println("请输入第三个整数:");
int num3 = sc.nextInt();
// 计算三个数中的最大值
int minValue = num1 < num2 ? (num1 < num3 ? num1 : num3):(num2 < num3 ? num2 : num3);
System.out.println(num1 + "、" + num2 + "、" + num3+ "这三个数中的最小值为:" + minValue);
// 计算三个的和
System.out.println(num1 + "、" + num2 + "、" + num3+ "这三个数的和:" + (num1+num2+num3));
}
}