Scanner键盘录入
import java.util.Scanner;
public class ScannerDemo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请录入一个数据 整数");
int x = sc.nextInt();
System.out.println("请录入第二个数据 整数");
int y = sc.nextInt();
System.out.println("x + y = " + (x + y));
}
}
import java.util.Scanner;
class ScannerTest2{
public static void main(String[] args) {
//创建对象
Scanner sc = new Scanner(System.in);
System.out.println("录入第一个数字(整数)!");
int x = sc.nextInt();
System.out.println("录入第二个数字(整数)!");
int y = sc.nextInt();
System.out.println("录入第三个数字(整数)!");
int z = sc.nextInt();
//System.out.println("前两个数是不是相等?"+(x==y));
//先判断x,y较大值
//int max1 = (x>y ? x : y);
//较大值跟z判断
// int max = (max1>z ? max1 : z);
//改进版方法 嵌套使用
int max = x > y ? (x>z ? x:z) : (y>z?y:z);
System.out.println("三个数的最大值是:!"+max);
}
}
转载于:https://blog.51cto.com/hexudong/1770840