Question
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 l: j++;
case 2: j++;
case 3: j++;
case 4: j++;
case 5: j++;
default: j++;
}
return j + x;
}
}
What will be the output of the program?
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 l: j++;
case 2: j++;
case 3: j++;
case 4: j++;
case 5: j++;
default: j++;
}
return j + x;
}
}
Answer: Option D
Was this answer helpful ?
Because there are no break statements, once the desired result is found, the program
continues though each of the remaining options.
Was this answer helpful ?
More Questions on This Topic :
Question 4.
public class While
{
public void loop()
{
....
Question 5.
switch(x)
{
default:
System.out.println("....
Submit Solution