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