流程控制之if

java中的流程控制語句主要包括選擇語句,循環語句,其中選擇語句又包括if語句,switch...case語句,循環語句包括while,do...while和for循環等機構。下面來分析分析if...else的用法

if選擇結構又分爲if單分支結構,if...else...雙分支結構,if...else if....else if ...else等多分支結構

單分支結構,顧名思義只有一個if結構。

int a =10;

if(a>5){

    System.out.println(''a>5);

}

這個例子就是單分支結構,顧名思義只有一個if選擇

下面看雙分支結構的,

int a = 10;

if(a>5){

 System.out.println(''a>5);

}else{

 System.out.println(''a<=5);

}

以上就是雙分支結構,顧名思義,二選一就是雙分支

還有一種選擇結構是if...else if...else if....else這種結構的

int score = 80;

if(score>=90){

    System.out.println(''A");

}else if(score>=80){

   System.out.println('B"");

}else if(score>=70){

   System.out.println('C"");

}else if(score>=60){

   System.out.println("D");

}else{

   System.out.println("E");

}

以上就是雙分支結構,顧名思義可以從多個選擇中選一個

具體內容請通過xuebiancheng8.com來觀看吧,網址是http://xuebiancheng8.com/play/goodgoodstudy_53_daydayup.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章