第三节 Java流程控制

条件语句

if-else if
    /*
        判断成绩好坏
            0-60 不及格
            60-80 及格
            80-90 良好
            90-100 优秀

     */
        //if语句
            int score = 75;
            if (score>0 && score<=60){
                System.out.println("不及格");
            }else if (score>60 && score<=80){
                System.out.println("及格");
            }else if(score>80 && score<=90){
                System.out.println("良好");
            }else if (score>90 && score<=100){
                System.out.println("优秀");
            }else {
                System.out.println("成绩不符合要求!");
            }
switch
    /*
        判断工作日与非工作日
     */
            int day = 6;
            switch (day){
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                    System.out.println("今天是工作日");
                    break;
                case 6:
                case 7:
                    System.out.println("今天是周末");
                    break;
                default:
                    System.out.println("输入的日期不符合规定!");
            }

循环语句

for语句
        //for语句
            for (int j=0;j<10;j++){
                System.out.println("hello world");
                i++;
            }
foreach语句
        //foreach语句
            int[] value={0,1,2,3,4,5,6,7,8,9};
            for(int k : value) {
                System.out.println("hello world"+k);
            }
while语句
    /*
        打印10个hello world
     */
        //while语句
            int i = 0;
            while (i<10){
                System.out.println("hello world");
                i++;
            }
do-while语句
        //do-while语句
            i=0;
            do{
                System.out.println("hello world");
                i++;
            }while (i<10);
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值