1.

Deepti works as a programmer in a travel company. She has developed the following code to display travel detail according to user’s choice. Help her in rewriting the same code using SWITCH CASE: if(choice==1) jTextField1.setText(“New Delhi to Goa”); else if(choice==2) jTextField1.setText(“New Delhi to Paris”); else if(choice==3) jTextField1.setText(“New Delhi to Bangkok”); else jTextField1.setText(“Pl. choose valid option”);

Answer»

switch(choice) 

case 1: 

jTextField1.setText(“New Delhi to Goa”); 

break; 

case 2: 

jTextField1.setText(“New Delhi to Paris”); 

break; 

case 3:

jTextField1.setText(“New Delhi to Bangkok”); 

break; 

default: 

jTextField1.setText(“Pl. choose valid option”); 

}



Discussion

No Comment Found

Related InterviewSolutions