三木915

导航

 

if单选结构

public static void main     
if(布尔表达式){
 
}
如果不满足if条件就直接跳过if进入下面的程序

示范程序(改编自狂的示范代码)

public class IfDemon03 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("please writer the number");
        String s = scanner.nextLine();
        if(s.equals("how is everything going")){
            System.out.println("everything is ok ,sir");
        }
        System.out.println("sir ,you have a phone call ");
     scanner.close();
    }

}

if双选择结构

if(布尔表达式){
    
}else{
    
}

if双选择结构示范代码

public class IfDemon01 {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        System.out.println("sir what kind people you want to be?");
        String s = scanner.nextLine();
        if(s.equals("I want to be the best people")){
            System.out.println("you must will be sir");
        }else {
            System.out.println("trust me sir you are the best keep up");
        }
        scanner.close();
    }
}

if多选择结构

if(布尔表达式1){
    ///如果布尔表达式1的值为true执行代码
}else if(布尔表达式2){
    //如果布尔表达式2的值为true执行代码
}else if(布尔表达式3){
    //如果布尔表达式3的值为true执行代码
}else{
    //如果以上布尔表达式都不为true执行代码
    
}/*if 语句至多有一个else语句,并且else语句必须在else if 语句之后
    if语句中可以有若干个else if ,一旦其中任何一个else if中的布尔表达式被满足则之后的else       if 和else语句都会直接被跳过。
    所以这里就要划分清楚每一个if 和 else if 中布尔表达式的判定范围,不要发生重叠。
    另外记住表示和的语法是 判断条件1 && 判断条件2
*/

if多选择结构示范代码

public class IfDemon02 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("welcome sir");
        String s = scanner.nextLine();
        if(s.equals("how is everything going jws")){
            System.out.println("everything take on sir");
        }else if(s.equals("do you think I'm mad?")){
            System.out.println("No sir i thought you good");
        }else if(s.equals("jws do you think bowen is fool?")){
            System.out.println("yes sir i thought he is");
        }else if(s.equals("do you think i can learn over at deadline?")){
            System.out.println("yes sir absolutely");
        }else if(s.equals("if I don't learn it over,what should I do?")){
            System.out.println("keep study sir never give up");
        }else{
            System.out.println("you are the best sir trust me");
        }
        scanner.close();
    }
}

tips:这里狂使用String 作为数据类型 而后利用是。s.equals("判断相等的语句")来进行判断。

posted on 2022-03-22 16:57  三木915  阅读(29)  评论(0编辑  收藏  举报