Java开发入门之第一阶段(九)——流程之判断语句练习(二)

语句练习

练习1

指定考试成绩,判断成绩的等级:

  • 90 - 100 优秀
  • 80 - 90 好
  • 70-80 良好
  • 70 - 60 及格
  • 60以下 不合格
public class if_else_if练习 {

	public static void main(String[] args) {
		int score = 100;
		if (score<0 || score >100) {
			System.out.println("你的成绩是错误的!");
		}else if(score>90 && score <=100) {
			System.out.println("成绩优秀!");
		}else if (score>80 && score<=90) {
			System.out.println("成绩好");
		}else if (score >70 && score <= 80) {
			System.out.println("成绩良好!");
		}else if (score >=60 && score <=70) {
			System.out.println("成绩及格!");
		}else {
			System.out.println("不及格!!!!!");
		}

	}

}

运行结果如下:
在这里插入图片描述

练习2

题目:
使用三元运算符和标准的if-else语句分别实现:取两个数字当中最大值

1.使用三元运算符:

public class test2 {

	public static void main(String[] args) {
		int a = 10;
		int b = 20;
		
		//首先使用三元运算符
		int max = a > b ? a : b;
		System.out.println("最大值" + max);
	}

}

结果如下:
在这里插入图片描述
2.使用if-else语句:

		int a = 10;
		int b = 20;
		int max;
		if (a > b) {
			max = a;
		}else {
			max = b;
		}
		System.out.println("最大值" + max);

结果和上面的是一样的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吃糖的霏霏子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值