64 615
Assignments Done
99,1%
Successfully Done
In September 2018

Answer to Question #3526 in Java | JSP | JSF for Y mukundareddy

Question #3526
5) Write a program to print the days in a week if 0=Sunday and 1=Monday and so on till Saturday by using switch-case.
Expert's answer
Create the file "DayOfWeek.java" with the following
contents:

//////////////////////////////
import
java.util.Scanner;

public class DayOfWeek
{
public static void
main (String[] args)
{
Scanner input = new Scanner(
System.in);
int day;
boolean flag;


System.out.print("Please enter a day number (0-6): ");
day =
input.nextInt();

switch (day) {
case
0:
System.out.printf("Sunday\n");
break;

case
1:
System.out.printf("Monday\n");
break;

case
2:
System.out.printf("Tuesday\n");
break;

case
3:
System.out.printf("Wednesday\n");
break;

case
4:
System.out.printf("Thursday\n");
break;

case
5:
System.out.printf("Friday\n");
break;

case
6:
System.out.printf("Saturday\n");
break;

default:
System.out.printf("Incorrect
number!\n");
break;

};

}
}
//////////////////////////



Compile it with


javac DayOfWeek.java

and run with

java DayOfWeek

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions