Answer to Question #326523 in Java | JSP | JSF for Jay

Question #326523

Consider the following table:

State a java program that use Switch structure to print one of the above statements depending on the

selected day. Write comments to explain your code.

day statement

Monday " Monday is the first day of the week !"

Tuesday " Tuesday is the second day of the week !"

Wednesday "Wednesday is the third day of the week !"

Thursday "Thursday is the fourth day of the week !"

Friday “Friday is the fourth day of the week !"

Saturday “Saturday is the fifth day of the week !"

Sunday “Sunday is the sixth day of the week !"

Any other day “ Unknown day !"


1
Expert's answer
2022-04-10T17:45:47-0400
import java.util.Scanner; //import Class Scanner

public class WeekDays {
    public static void main(String[] args) {
        Scanner scan= new Scanner(System.in);  //Create object scanner
        System.out.print("Choose one day of the week: ");   //Print massage
        String weekDay= scan.nextLine(); //variable that will get word from user

        switch(weekDay){
            case "Monday":                                               //first case
                System.out.println("Monday is the first day of the week !");//Print massage if variable weekDay=Monday
                break;
            case "Tuesday":                                                //second case
                System.out.println("Tuesday is the second day of the week !");
                break;
            case "Wednesday":
                System.out.println("Wednesday is the third day of the week !");
                break;
            case "Thursday":
                System.out.println("Thursday is the fourth day of the week");
                break;
            case "Friday":
                System.out.println("Friday is the fifth day of the week !");
                break;
            case "Saturday":
                System.out.println("Saturday is the fifth day of the week !");
                break;
            case "Sunday":
                System.out.println("Sunday is the sixth day of the week !");
                break;
            default:                                            //Case when no option is suitable
                System.out.println("Unknown day !");
        }

    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS