(This for java)
Have to find the value of z
int y= 3;
int z =4;
switch (y+4) {
case 6: z=2; break;
case 7: z=3; break;
default: z+=5;
}
Answer: The value of z is equal to 3.Because in switch statement given y+4 which is equal to 7 as y=3.Then case 7 in the switch statement executes.In this the variable z is assigned as 3.Therefore the value of z is 3.The below program shows this.
Code:
public class Test
{
public static void main(String args[])
{
int y = 3;
int z = 4;
switch(y+4)
{
case 6: z = 2;
break;
case 7: z = 3;
break;
default: z += 5;
}
System.out.println("The value of z is: "+z);
}
}
Screenshot:
Output:
Get Answers For Free
Most questions answered within 1 hours.