import java.util.Scanner;
public class Max {
//输入3个数字,求最大值并输出
public static void main(String[] args) {
// 读取键盘输入信息
Scanner s = new Scanner(System.in);
// 提示输入3个数字
System.out.println("请输入3个数字");
// 定义a,b,c的值
int a = s.nextInt();
int b = s.nextInt();
int c = s.nextInt();
// 声明最大值为max
int max;
// 比较a和b最大的值为max
if (a > b) {
max = a;
} else {
max = b;
}
// a和b中的最大值max再和c比较,若比c小,则max为c
if (c > max) {
max = c;
}
// 输出结果
System.out.println("最大值是" + max);
}
}
[Java]输入3个数字,求最大值并输出
最新推荐文章于 2024-03-17 20:11:25 发布