日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux运维系统工程师与java基础学习系列-6

發(fā)布時(shí)間:2024/4/13 linux 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux运维系统工程师与java基础学习系列-6 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Java天生驕傲系列-6

?程序流程控制(續(xù))

? ?循環(huán)結(jié)構(gòu)

? ? ? ??代表語句:while, do while, for

? ? While語句格式

? ? ? ? while(條件表達(dá)式)

? ? ? ? ? ? {

? ? ? ? ? ? ??執(zhí)行語句;

? ? ? ? ? ??}


? ? ? ? ? ? ?牛刀小試:

???????????package test.myeclipse;

? ? ? ? ? ? ?publicclass test1 {

?

??????????????publicstaticvoid main(String[] args) {

???????????????????????int x=1;

? ? ? ? ? ? ? ? ? ? ? ??while (x<4)

? ? ? ? ? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("x="+x);

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? x++;

??????????

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

??????

??????

??????

?

? ? ? ? ? ? ? ? }

? ? ? ? ? ??}

????????????????????????運(yùn)行結(jié)果: x=1

x=2

? ? ? ? ? ? ? ? ? ? ? ? x=3




???do while 語句格式

?????????????????????? do

?????????????????????? {

????????????????????????????執(zhí)行語句;

?????????????}while(條件表達(dá)式)

????????????????????????????牛刀小試:

package test.myeclipse;?

publicclass test1 {

???????????????????????????????publicstaticvoid main(String[] args) {

??????????????????????????????? int x=1;

??????????????????????????????? do

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {

?????????????????????????????????? System.out.println("x="+x);

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? x++;

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }while(x<4);

??????

??????

??????

?

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }

?

? ? ? ? ? ? ? ? ? ? ? ? ? }

運(yùn)行結(jié)果:

x=1

x=2

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? x=3


??for語句格式:

? ? for(初始化表達(dá)式;循環(huán)條件表達(dá)式;循環(huán)后的操作表達(dá)式)

? ? ? ?{

? ? ? ? ? ? ?執(zhí)行語句;

? ? ? ?}

? ? ? ? ? ? ?牛刀小試:

????????????????package test.myeclipse;

? ? ? ? ? ? ? ? ??publicclass test1 {? ?

???????????????????publicstaticvoid main(String[] args) {

?????????????????????for (int x=1;x<4;x++)

? ? ? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? ?System.out.println("x="+x);

? ? ? ? ? ? ? ? ? ? ? ? }?????

?

? ? ? ? ? ? ? ? ? ? ?}

?

?????????????????}

? ? ? ? ? ? ? ? ?運(yùn)行結(jié)果:

? ? ? ? ? ? ? ? ? ? x=1

? ? ? ? ? ? ? ? ? ??x=2

? ? ? ? ? ? ? ? ? ? x=3


? ?

? ? ? 練習(xí)一例:

????? ????package test.myeclipse;?

publicclass test1 {?

?????? ?????????? publicstaticvoid main(String[]args) {

?????????? ?????????? int x=1;

?????????? ?????????? for (System.out.println("a");x<3;System.out.println("c"))

?????????? ?????????? {

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

????????????? ?????????? x++;

?????????? ?????????? }?????

?

??? ????????????? }

?

? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? 運(yùn)行結(jié)果:

a

d

c

d

c



?語句嵌套

????? 牛刀小試1

????????????????? package test.myeclipse;?

? ? ? ? ? ?publicclass test1 {

?

? ? ? ? ? ? ? ? ? ? ?publicstaticvoid main(String[]args) {

??????????

? ? ? ? ? ? ? ? ? ? ? ??for (int x=0;x<3;x++)

? ? ? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? ? ??for(int y=0;y<4;y++)

? ? ? ? ? ? ? ? ? ? ? ? ? ? {

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

? ? ? ? ? ? ? ? ? ? ? ? ? ? }?????

? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ?}

?

? ? ? ? ? ?}

????運(yùn)行結(jié)果:

????? ? ? ? ? ?ok

????ok

????ok

????ok

????ok

????ok

????ok

????ok

????ok

????ok

????ok

????ok

? ? ? ?牛刀小試2

????????????????package test.myeclipse;

? ? ? ? ? ? ? ? public ?class test1 {?

? ? ? ? ? ? ? ? ? ??publicstaticvoid main(String[]args) {

? ? ? ? ? ? ? ? ? ? ?int z=5;

? ? ? ? ? ? ? ? ? ? ?for (int x=0;x<5;x++)

? ? ? ? ? ? ? ? ? ? ?{

? ? ? ? ? ? ? ? ? ? ? ??for(int y=0;y<z;y++)

? ? ? ? ? ? ? ? ? ? ? ? {

????????????????? ??? ??? System.out.print("*");

? ? ? ? ? ? ? ? ? ? ? ? }??

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

? ? ? ? ? ? ? ? ? ? ? ? ? ?z--;

? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? }

?

? ? ? ? ?}

????????運(yùn)行結(jié)果:

?????????????? *****

????????****

????????***

????????**

????????*


????????????優(yōu)化一下:

????? ????package test.myeclipse;?

??????????publicclass test1 {?

?????? ????????publicstaticvoid main(String[] args) {

?????????? ????????for (int x=0;x<5;x++)

?????????????????? {

????????????? ????????for(int y=x;y<5;y++)

????????????? ????? ??{

? ? ? ? ? ? ? ? ? ? ? ? ?System.out.print("*");

? ? ? ? ? ? ? ? ? ? }??

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

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

? ? ? ? ? ? ? ? ? ?}

? ? ? ? ? ? ? ?}

?

? ? ? ? ? ? ?}

????運(yùn)行結(jié)果:

?????????? *****

????****

????***

????**

????? ? ? ?*



未完待續(xù)。。。。。。



轉(zhuǎn)載于:https://blog.51cto.com/2489843/1541986

總結(jié)

以上是生活随笔為你收集整理的Linux运维系统工程师与java基础学习系列-6的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。