JAVA chapter2

数据测试

if ...else if   and else;

  1. 正确数据
  2. 边界数据
  3. 错误数据
    if (score >100 || score<0) {
        System.out.println(" illegal input"); \\ the illegal input
    
    
    
    } else if (score >=95 || score<=100) {
        System.out.println("####");            \\the border and the true statistic
    
    
    } else if (score>=0||score <=95){
        System.out.println("###")
    }

switch

switch(variable){
    case value1:
            statemen;
            break;        \\the break of each case in not a must, but if it disappear, it                      
                          \\program will execute the next case until the break appear. 
    case value2:
            statement;
            break;
......
    default:
            statement    \\the default branch doesnot need a break statement
}

public static void main(String[] args){

    int num =3;

    switch (num){
        case 1:
            System.out.println("the value is 1");
            break;

        case 2:
            System.out.println("the value is 2");
            break;

        case 3:
            System.out.println("the value is 3");
            break;
    
    }
}

while loop

while (boolean expression){
        statement;            \\if the boolean expression is true the loop will continue             
                              \\executing;
}

 for loop

for (initial; boolean expression; update){
        statement;
}

\\

public static void main(String[] args){

        for (int x=1; x<=10; x++){

          System.out.println(x);  
    }
}

 do while

do{
    System.out.println(x);     \\do...while loop is executed at least once
} while (boolean expression)   \\the loop will end until the boolean expression is false

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值