import java.util.Scanner;
/*题目:
键盘输入三个int数字,然后求出其中的最大值。
思路:
1.键盘输入要用Scanner
2.Scanner三个步骤,导包,创建使用nextInt()方法
3.因为是三个数字,所以要调用三次nextInt()方法,得到三个int变量
4.无法同时判断三个数字谁最大,应该转换成为两个步骤:
4.1首先判断前两个当中谁最大,拿到前两个的最大值
4.2拿着前两个的最大值,再和第三个数字比较,得到三个数字当中的最大值
5.打印最终结果*/
public class Demo03ScannerMax {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入第一个数字");
int a = sc.nextInt();
System.out.println("请输入第二个数字");
int b = sc.nextInt();
System.out.println("请输入第三个数字");
int c = sc.nextInt();
//首先得到前两个数字当中的最大值
int t=(a>b?a:b);
int max=(t>c?t:c);
System.out.println("您输入的三个数中最大的数是:"+max);
}
}
求出三个数中的最大值
最新推荐文章于 2024-05-02 08:00:00 发布