Showing results for 
Search instead for 
Did you mean: 

switch case

Former Member
0 Kudos

hello ! i m a beginner in java. Kindly help me to solve this question.

Wat’ll happen when u compile and run this code

public class MySwitch{

public static void main(String argv[]){

MySwitch ms=new MySwitch();



public void amethod(){

int k=10;


default: // do nothing

System.out.println("this is the default output");


case 10; System.out.println("ten");

case 20: System.out.println("twenty");break;





1. none of these options

2. Compile time error target of switch must be an integral type

3.Compile and run with output " thid is the default output"

4.Compile and run with output of the single line "ten"

View Entire Topic
Active Contributor
0 Kudos

Hi Payal,

You code will give following error:

java.lang.Error: Unresolved compilation problem:

Syntax error on token ";", ":" expected.

because case 10; should be changed to case 10: then it will give output:



you have to put break; between case 10 and case 20 then output will be: ten

You can also test these small program in NWDS.

see this link also:

Regards, Suresh KB