classExample{staticvoidmain(String[] args){//Initializing 2 variables i and j int i =0;int j =1;// First evaluating the value of variable i switch(i){case0:// Next evaluating the value of variable j switch(j){case0:println("i is 0, j is 0");break;case1:println("i is 0, j is 1");break;// The default condition for the inner switch statement default:println("nested default case!!");}break;// The default condition for the outer switch statement default:println("No matching case found!!");}}}
在上面的例子中,我们首先将变量 a 的值初始化为 2。然后我们有一个 switch 语句来计算变量 a 的值 。 根据变量的值,它将执行相关的 case 语句集。 上述代码的输出将是 -