想必在大家生活中都有过遇到三个数字无法比较大小的尴尬时刻,那么随时掌握这个程序能在生活中大大减少生活中尴尬的场景,提高做事的效率。
import java.util.Scanner;
public class add {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
Scanner bc = new Scanner(System.in);
int b = bc.nextInt();
Scanner ac = new Scanner(System.in);
int c = ac.nextInt();
int e=a>b?a:b;
int f=e>c?e:c;
System.out.println(f);
}
}
里面高深的原理主要是键盘录入跟三元运算符,通过录入三个数定义abc再通过三元运算符一个进阶套嵌用法定义e为ab之间大的数在定义f比比较c跟e之间的大小自然而然就选出了三个数之间最大的数f,最后在输出f就能得出正确结论了。
这套模板不仅能比较三个数之间大小,大家可以通过不管的对叠套嵌能比较更多的数