Answer to Question #276093 in Java | JSP | JSF for Candy

Question #276093

Write a subroutine named "printDayofWeek" that will output the day of the week for a given number. Use Swtich-case. For example, the command "1” would output “Sunday”. (10 marks)


1
Expert's answer
2021-12-06T05:26:43-0500


package printdayofweek;


import java.util.Scanner;




public class PrintDayofWeek {


    
    public static void main(String[] args) {
        Scanner scan  = new Scanner(System.in);
        System.out.println("Enter the  number ");
        int day = scan.nextInt();
        switch(day){
            case 1:
                System.out.println("Sunday");
                break;
                
            case 2:
                System.out.println("Monday");
                break;
                
            case 3:
                System.out.println("Tuesday");
                break;
                
            case 4:
                System.out.println("Wednesday");
                break;
                
            case 5:
                System.out.println("Thursday");
                break;
                
            case 6:
                System.out.println("Friday");
                break;
            case 7:
                System.out.println("Saturday");
                break;
           
        }
    }
    
}

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