博客
关于我
[JavaSE-03]流程控制语句
阅读量:96 次
发布时间:2019-02-26

本文共 3006 字,大约阅读时间需要 10 分钟。

?????????

1. ????

?????????????????????????????????????????????????????????????

1.1 ????

public static void main(String[] args) {    System.out.println(1);    System.out.println(2);    System.out.println(3);}

????????????????


2. ????

2.1 ?????? if

public static void main(String[] args) {    System.out.println("??");    int a = 10;    int b = 20;    if (a == b) {        System.out.println("a??b");    }    int c = 10;    if (a == c) {        System.out.println("a??c");    }    System.out.println("??");}

????????if???????????????????

2.2 if?else ??

public static void main(String[] args) {    int a = 1;    if (a % 2 == 0) {        System.out.println("a???");    } else {        System.out.println("a???");    }    System.out.println("??");}

??if?else??????????????????????????

2.3 if?else if ??

public static void main(String[] args) {    int x = 5;    int y;    if (x >= 3) {        y = 2 * x + 1;    } else if (x >= -1 && x < 3) {        y = 2 * x;    } else {        y = 2 * x - 1;    }    System.out.println("y????" + y);}

????????????????????????


3. ???? switch

switch?????????????????????????????byte?short?int?char?enum???JDK7????String???

public static void main(String[] args) {    int weekday = 6;    switch (weekday) {        case 1:            System.out.println("???");            break;        case 2:            System.out.println("???");            break;        case 3:            System.out.println("???");            break;        case 4:            System.out.println("???");            break;        case 5:            System.out.println("???");            break;        case 6:            System.out.println("???");            break;        case 7:            System.out.println("???");            break;        default:            System.out.println("????????");            break;    }}

?????case????break?????????????case???????


4. ????

????????????????????????

4.1 for??

// ??10?"HelloWorld"for (int x = 0; x < 10; x++) {    System.out.println("HelloWorld" + x);}
// ??1-100??????int sum = 0;for (int i = 1; i <= 100; i++) {    if (i % 2 == 0) {        sum += i;    }}System.out.println("sum?" + sum);

4.2 while??

public static void main(String[] args) {    int i = 1;    while (i <= 10) {        System.out.println("HelloWorld");        i++;    }}

while???????????????

4.3 do?while??

public static void main(String[] args) {    int x = 1;    do {        System.out.println("HelloWorld");        x++;    } while (x <= 10);}

do?while????????????????????????????????


5. ????

5.1 break??

????switch??????????????

public static void main(String[] args) {    for (int i = 1; i <= 10; i++) {        if (i == 3) {            break;        }        System.out.println("HelloWorld" + i);    }}

5.2 continue??

???????????????????

public static void main(String[] args) {    for (int i = 1; i <= 10; i++) {        if (i == 3) {            continue;        }        System.out.println("HelloWorld" + i);    }}

??

??????if?switch?for?while???????????????????????????????????????????????????

转载地址:http://kyg.baihongyu.com/

你可能感兴趣的文章
MySQL 证明为什么用limit时,offset很大会影响性能
查看>>
mysql 递归查找父节点_MySQL递归查询树状表的子节点、父节点具体实现
查看>>
mysql 里对root及普通用户赋权及更改密码的一些命令
查看>>
Mysql 重置自增列的开始序号
查看>>
MySQL 高可用性之keepalived+mysql双主
查看>>
mysql5.6.21重置数据库的root密码
查看>>
MySQL5.6忘记root密码(win平台)
查看>>
mysql5.7 for windows_MySQL 5.7 for Windows 解压缩版配置安装
查看>>
MySQL5.7.18主从复制搭建(一主一从)
查看>>
MySQL5.7.19-win64安装启动
查看>>
mysql5.7性能调优my.ini
查看>>
Mysql5.7深入学习 1.MySQL 5.7 中的新增功能
查看>>
Mysql5.7版本单机版my.cnf配置文件
查看>>
mysql5.7的安装和Navicat的安装
查看>>
mysql5.7示例数据库_Linux MySQL5.7多实例数据库配置
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
查看>>
mysql8的安装与卸载
查看>>
mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
查看>>