Scanner练习-键盘输入两个数字求和与键盘输入三个数字求最大值
Scanner练习-键盘输入两个数字求和
Scanner sc1 = new Scanner(System.in) ; System. out.println("请输入第一个数字:"); int a = sc1.nextInt(); System.out.println("请输入第二个数字:"); int b = sc1.nextInt(); int result = a + b; System.out.println("结果是:" + result);
键盘输入三个数字求最大值
Scanner sc2 = new Scanner(System.in) ; System.out.println("请输入第一个数字:"); int a1 = sc.nextInt(); System.out.println("请输入第二个数字:"); int b2 = sc.nextInt(); System.out.println("请输入第三个数字:"); int c = sc.nextInt(); //首先得到前两个数字当中的最大值 int temp = a1 > b2 ? a1 : b2; int max = temp > c ?temp : c; System.out.println("最大值是:" + max) ;

浙公网安备 33010602011771号