以下以三个和尚为例
1.导包:
import java.util.Scanner;
要在class之前
创建对象:
Scanner sc=new Scanner(System.in);
2.输入:
int height1=sc.nextInt;
int height2=sc.nextInt;
int height3=sc.nextInt;
3.比较输出:
import java.util.Scanner;
public class Xunlain4 {
public static void main(String[] args) {
//输入身高,单位厘米
Scanner sc=new Scanner(System.in);
System.out.println("输入第一个和尚的身高:");
int height1=sc.nextInt();
System.out.println("输入第二个和尚的身高:");
int height2=sc.nextInt();
System.out.println("输入第三个和尚的身高:");
int height3=sc.nextInt();
//比较身高
int max1=height1>height2?height1:height2;
int max2=max1>height3?max1:height3;
//输入最高的身高
System.out.println("最高的和尚身高是:"+max2);
}
}