1.

Write the equivalent switch statement for the following: int Ch;Ch=Integer.parseInt(ChTextField.getText());if(Ch = = 1){System.out.println(‘‘ Arts”);}else If(Ch = = 2){System.out.println(“ Commerce”);}else if(Ch= = 3){System.out.println(“Science”);}else{System.out.println(“Invalid Entry”);}

Answer»

int Ch;

Ch=Integer.parseInt(ChTextField.getText());

switch(Ch)

{

case ‘1’ : System.out.println(“Arts”);

break;

case ‘2’: System.out.println(Commerce);

break;

case ‘3’: System.out.println(Science);

break;

default: System.out.println(Invalid Entry);

}



Discussion

No Comment Found

Related InterviewSolutions