国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

break和continue的使用

2022-06-05 20:55 作者:虛云幻仙  | 我要投稿

/**
* 測試break和continue語句
*/

public class TestBreak {
? ?public static void main(String[] args) {
? ? ? ?while (true){
? ? ? ? ? ?//條件為true導(dǎo)致無限循環(huán)
? ? ? ? ? ?int i = (int)(Math.random()*101);
? ? ? ? ? ?//循環(huán)內(nèi)定義的變量退出循環(huán)后消失
? ? ? ? ? ?System.out.println(i);
? ? ? ? ? ?if (i==88){
? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ?//遇到break會強(qiáng)制退出循環(huán),死循環(huán)中止
? ? ? ? ? ?}
? ? ? ?}

? ? ? ?int count = 0;
? ? ? ?for(int i = 100;i<=150;i++){
? ? ? ? ? ?if(i%3==0)continue;
? ? ? ? ? ?System.out.print(i+" ");
? ? ? ? ? ?count++;
? ? ? ? ? ?if(count%5==0){
? ? ? ? ? ? ? ?System.out.println();
? ? ? ? ? ?}
? ? ? ?}

? ? ? ?System.out.println();

? ? ? ?outer:for (int i = 100;i<=150;i++){
? ? ? ? ? ?//跳轉(zhuǎn)用outer 帶標(biāo)簽的coutinue
? ? ? ? ? ?for(int j = 2;j<i/2;j++){
? ? ? ? ? ? ? ?if (i%j==0){
? ? ? ? ? ? ? ? ? ?continue outer;
? ? ? ? ? ? ? ? ? ?//回到outer行 進(jìn)行下一個(gè)循環(huán)
? ? ? ? ? ? ? ?}
? ? ? ? ? ?}
? ? ? ? ? ?System.out.print(i+" ");
? ? ? ?}

? ? ? ?System.out.println();

? ? ? ?count = 0;
? ? ? ?for (int i = 100;i<=150;i++){
? ? ? ? ? ?for (int j = 2;i>=j*j;j++){
? ? ? ? ? ? ? ?if (i%j==0){
? ? ? ? ? ? ? ? ? ?count = 1;
? ? ? ? ? ? ? ? ? ?break;

//break會強(qiáng)制退出當(dāng)前循環(huán),這里會回到上一層循環(huán)繼續(xù)

? ? ? ? ? ? ? ?}
? ? ? ? ? ?}
? ? ? ? ? ?if (count==0){
? ? ? ? ? ? ? ?System.out.print(i+" ");
? ? ? ? ? ?}
? ? ? ? ? ?count = 0;
? ? ? ?}
? ?}
}

break和continue的使用的評論 (共 條)

分享到微博請遵守國家法律
淳化县| 铅山县| 新平| 临潭县| 敖汉旗| 大丰市| 沙雅县| 称多县| 德保县| 利津县| 孙吴县| 西城区| 济源市| 南木林县| 长丰县| 安顺市| 枣阳市| 临沧市| 灵台县| 新营市| 广宁县| 恩施市| 观塘区| 莱西市| 临泽县| 涪陵区| 平陆县| 平塘县| 抚顺市| 宣恩县| 牡丹江市| 合作市| 江华| 莫力| 乌什县| 绥滨县| 定南县| 凉城县| 正宁县| 满洲里市| 宣恩县|