好的,这里是 Java 代码来比较三个数的大小:
import java.util.Scanner;// 导入 Scanner 类
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); // 创建 Scanner 对象
System.out.println("请输入第一个数:");
int a = sc.nextInt(); // 读取第一个数
System.out.println("请输入第二个数:");
int b = sc.nextInt(); // 读取第二个数
System.out.println("请输入第三个数:");
int c = sc.nextInt(); // 读取第三个数
// 判断三个数的大小关系
if (a > b) {
if (a > c) {
System.out.println("最大的数是:" + a);
} else {
System.out.println("最大的数是:" + c);
}
} else {
if (b > c) {
System.out.println("最大的数是:" + b);
} else {
System.out.println("最大的数是:" + c);
}
}
}
}
在这段代码中,我们使用了 Scanner 类来读取键盘输入的数据。具体来说,我们使用了 sc.nextInt()
方法来读取整数。然后,我们使用了 if 语句来比较三个数的大小关系,并输出最大的数。
希望这段代码能帮到你!