java流程控制语句

if语句

 

 

 

 示例:

package ydd.yj.demo1;

import java.util.Scanner;

public class helloword {
    //快速生成"psvm"  生成如下
    public static void main(String[] args) {
        //快速生成"sout" 生成如下
        //if语句
        /*if (关系表达式) {
            语句体;*/
        Scanner sc = new Scanner(System.in);
        int win = sc.nextInt();
        if (win > 2) {
            System.out.println("小伙子酒量不错");
        }
    }
}

if的第二种模式

 

 示例

public class helloword {
    //快速生成"psvm"  生成如下
    public static void main(String[] args) {
        //快速生成"sout" 生成如下
        //if语句
        /*if (关系表达式) {
            语句体;*/
        Scanner sc = new Scanner(System.in);
        int win = sc.nextInt();
        if (win > 2) {
            System.out.println("小伙子酒量不错");
        }else {
            System.out.println("小伙纸你又觉得自己可以了?");
        }
    }
}

if的第三种表现形式

 

import java.util.Scanner;

public class helloword {
    //快速生成"psvm"  生成如下
    public static void main(String[] args) {
        //快速生成"sout" 生成如下
        //if语句
        /*if (关系表达式) {
            语句体;*/
        Scanner sc = new Scanner(System.in);
        int win = sc.nextInt();
        if (win > 2) {
            System.out.println("小伙子酒量不错");
        }else if(win==1){
            System.out.println("小伙纸你又觉得自己可以了?");
        }else {
            System.out.println("你能喝都是负的,哎垃圾");
        };
    }
}

 

posted @ 2022-05-13 15:08  欧阳锦涛  阅读(35)  评论(0)    收藏  举报
TOP 底部