单选题:Java语言中,下面程序运行后得到的结果是?
Java语言中,下面程序运行后得到的结果是?
public class SwitchTest{
public static void main (String[] args){
System.out.println("Value = "+switchIt(4));
}
public static int switchIt (int x ) {
int j = 1;
switch (x) {
case 1: j++ ;
case 2: j++ ;
case 3: j++;
case 4: j++;
case 5: j++;
default : j++;
}
return j + x;
}
}
A.Value = 3
B.Value = 4
C.Value = 7
D.Value = 8
答案:D
public class SwitchTest{
public static void main (String[] args){
System.out.println("Value = "+switchIt(4));
}
public static int switchIt (int x ) {
int j = 1;
switch (x) {
case 1: j++ ;
case 2: j++ ;
case 3: j++;
case 4: j++;
case 5: j++;
default : j++;
}
return j + x;
}
}
A.Value = 3
B.Value = 4
C.Value = 7
D.Value = 8
答案:D