3个值中取出最大值

import java.util.Scanner;
public class C5 {
public static void main(String[] args) {
int a = 1;
int b = 2;
System.out.println("a:"+a);
System.out.println("b:"+b);
System.out.println("请输入C的值");
int c = new Scanner(System.in).nextInt();

int max ;
/*用三元运算的方法 ?:
int max1 = a > b? a: b ;
System.out.println("a和b中的最大值"+max1);

int max2 = max1>c ? max1 : c;
System.out.println("a和b和c中的最大值"+max2);
*/

// 用if的方法
if (a>=b & a>=c){
max = a;
}else if(b>=a & b>=c){
max = b;
}else{
max =c;
}
System.out.println(max);

}
}
posted @ 2020-10-09 19:41  Liang-shi  阅读(342)  评论(0)    收藏  举报