/*
录入三个数据,获取三个数中的最大值
*/
import java.util.Scanner;
class ScannerTest1{
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();
if (a >= b & a >= c){
int max = a;
System.out.println("max:"+a);
}
else if (b >= a & b >= c){
int max = b;
System.out.println("max:"+b);
}
else if (c >= a & c >= b){
int max = c;
System.out.println("max:"+c);
}
else{
System.out.println("输入有误!");
}
//int temp = ((a > b)? a:b);
//int max = ((temp > c)? temp:c);
//System.out.println("max:"+max);
}
}
Java键盘录入三个数比较大小
最新推荐文章于 2023-04-03 17:31:17 发布