Following is the java program to print the days of a week.
DisplayDays.java:
----------------------------------
public class DisplayDays {
public static void main(String[] args){
//Initialize array
int[] daysArray = {1, 2, 3, 4, 5, 6, 7};
//Loop through array
for(int i = 0; i < daysArray.length; i++){
//Get day
int day = daysArray[i];
//Switch-case structure
switch(day){
case 1: System.out.println(day + " = Sunday"); break;
case 2: System.out.println(day + " = Monday"); break;
case 3: System.out.println(day + " = Tuesday"); break;
case 4: System.out.println(day + " = Wednesday"); break;
case 5: System.out.println(day + " = Thursday"); break;
case 6: System.out.println(day + " = Friday"); break;
case 7: System.out.println(day + " = Saturday"); break;
default:;
}
}
}
}
/******************************* Output *********************************/
1 = Sunday
2 = Monday
3 = Tuesday
4 = Wednesday
5 = Thursday
6 = Friday
7 = Saturday
As we have used a for loop to print all the days of a week. At each time one case statement is executed. You can also do it by user input. when user press 1 , case 1 will be executed and Sunday will be printed.
4