Write a Java program that keeps a number from the user and generates an integer between 1 and 7 and displays the name of the weekday.
Code
public class Switch1 {
public static void main(String args[]){
int a = 1;
String DayS;
String DayString;
switch (a) {
case 1:
DayString="Monday";
break;
case 2:
DayString="Tuesday";
break;
case 3:
DayString="Wednesday";
break;
case 4:
DayString="Thursday";
break;
case 5:
DayString="Friday";
break;
case 6:
DayString="Saturday";
break;
case 7:
DayString="Sunday";
break;
default:
DayString ="Invalid Number";
break;
}
System.out.println(DayString);
}
}
Output
Monday
0 Comments