Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
+1 vote
4.7k views
in Information Technology by (71.3k points)

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");

else

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

1 Answer

+2 votes
by (76.5k points)
selected by
 
Best 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");

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...