博客
关于我
[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创建数据库和用户 并授权
查看>>
mysql创建数据库指定字符集
查看>>
MySql创建数据表
查看>>
MySQL创建新用户以及ERROR 1396 (HY000)问题解决
查看>>
MySQL创建用户与授权
查看>>
MySQL创建用户报错:ERROR 1396 (HY000): Operation CREATE USER failed for 'slave'@'%'
查看>>
MySQL创建索引时提示“Specified key was too long; max key length is 767 bytes”
查看>>
mysql初始密码错误问题
查看>>
MySQL删除数据几种情况以及是否释放磁盘空间【转】
查看>>
Mysql删除重复数据通用SQL
查看>>
mysql判断某一张表是否存在的sql语句以及方法
查看>>
mysql加入安装策略_一键安装mysql5.7及密码策略修改方法
查看>>
mysql加强(1)~用户权限介绍、分别使用客户端工具和命令来创建用户和分配权限
查看>>
mysql加强(3)~分组(统计)查询
查看>>
mysql加强(4)~多表查询:笛卡尔积、消除笛卡尔积操作(等值、非等值连接),内连接(隐式连接、显示连接)、外连接、自连接
查看>>
mysql加强(5)~DML 增删改操作和 DQL 查询操作
查看>>
mysql加强(6)~子查询简单介绍、子查询分类
查看>>
mysql加强(7)~事务、事务并发、解决事务并发的方法
查看>>
MySQL千万级多表关联SQL语句调优
查看>>
mysql千万级大数据SQL查询优化
查看>>