java3

三元运算符:
public static void main(String[] args) {

int p1 = 150;
int p2 = 210;
int p3 = 165;

int max = p1 > p2 ? p1 : p2;

int max2 = max > p3 ? max : p3;

System.out.println(max2);
if判断语句:
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个成绩");
int score = sc.nextInt();

if (score >= 0 && score <= 100) {
if (score >= 95 && score <= 100) {
System.out.println("优秀");
} else if (score >= 90 && score <= 94) {
System.out.println("一般");
} else if (score >= 80 && score <= 89) {
System.out.println("平庸");
} else {
System.out.println("菜鸟");
}
} else {
System.out.println("成绩异常");
}
posted @ 2024-04-25 19:55  唐青云  阅读(7)  评论(0)    收藏  举报