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)
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;
}
}
}
Comments
Leave a comment