Page 59 - CTS - CSA TP - Volume 2
P. 59
COMPUTER SOFTWARE APPLICATION - CITS
TASK 2 : Day of the week using a switch statement
import java.util.Scanner;
public class DayOfWeek {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print(“Enter a number (1-7) representing a day of the week: “);
int day = scanner.nextInt();
String dayName;
switch (day) {
case 1:
dayName = “Sunday”;
break;
case 2:
dayName = “Monday”;
break;
case 3:
dayName = “Tuesday”;
break;
case 4:
dayName = “Wednesday”;
break;
44
CITS : IT & ITES - Computer Software Application - Exercise 86