无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(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的使用的評論 (共 條)

分享到微博請遵守國家法律
利辛县| 齐河县| 临沧市| 浪卡子县| 沛县| 克什克腾旗| 新密市| 潮州市| 沛县| 玉山县| 灌阳县| 额济纳旗| 得荣县| 太白县| 桐梓县| 金华市| 临湘市| 双流县| 麦盖提县| 永修县| 新民市| 社旗县| 巴楚县| 偃师市| 河南省| 旺苍县| 增城市| 凤山县| 镇坪县| 微博| 富宁县| 加查县| 江陵县| 凌海市| 荣昌县| 高要市| 海阳市| 栖霞市| 南靖县| 高邑县| 梓潼县|