Java-nested-if-statements-in-java
提供:Dev Guides
Javaのネストされたifステートメント
if-elseステートメントをネストすることは常に有効です。つまり、ifまたはelse ifステートメントを別のifまたはelse ifステートメントの中に使用できます。
構文
ネストされたif … elseの構文は次のとおりです-
if(Boolean_expression 1) {
//Executes when the Boolean expression 1 is true
if(Boolean_expression 2) {
//Executes when the Boolean expression 2 is true
}
}
_if_ステートメントをネストしたのと同様の方法で、 else if … else をネストできます。
例
public class Test {
public static void main(String args[]) {
int x = 30;
int y = 10;
if( x == 30 ) {
if( y == 10 ) {
System.out.print("X = 30 and Y = 10");
}
}
}
}
これは、次の結果を生成します-
出力
X = 30 and Y = 10