最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

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

分享到微博請遵守國家法律
宝兴县| 仁布县| 上饶市| 忻州市| 宁远县| 高邮市| 南宫市| 莱西市| 昌平区| 射阳县| 禹城市| 常宁市| 鄢陵县| 西青区| 柳林县| 汶川县| 彰化县| 上虞市| 浦江县| 阿克| 习水县| 沁源县| 民权县| 邯郸县| 呼玛县| 缙云县| 讷河市| 开原市| 淳安县| 安陆市| 临武县| 伊通| 乡宁县| 济阳县| 锡林浩特市| 北票市| 温泉县| 贡嘎县| 云霄县| 高要市| 洪雅县|