1.

Rewrite the following code using switch case:int day=Integer.parseInt(jTextField1.getText());if(day>=1 && day<=5)jOptionPane1.showMessageDialog(this, "Working Day");else if(day>=6 && day<=7)jOptionPane1.showMessageDialog(this, "Off Day");elsejOptionPane1.showMessageDialog(this, "Invalid Entry");

Answer»

int day=Integer.parseInt(jTextField1.getText());

switch(day)

{

case 1:

case 2:

case 3:

case 4:

case 5:

jOptionPane1.showMessageDialog(this, "Working Day"); break;

case 6:

case 7:

jOptionPane1.showMessageDialog(this, "Off Day"); break;

default:

jOptionPane1.showMessageDialog(this, "Invalid Entry");

}



Discussion

No Comment Found

Related InterviewSolutions