/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch3.java |
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
package com.calebfontenot.lab8_calebfontenot;
import java.util.Scanner;
public class Switch3 {
public static void main(String[] args) {
int dayOfWeekInt;
String dayOfWeekString = "nullday",
ordinal = "0th";
Scanner input = new Scanner(System.in);
System.out.print("Enter a number that signifies a day of the week: ");
dayOfWeekInt = input.nextInt();
switch (dayOfWeekInt) {
case 1:
dayOfWeekString = "Sunday";
ordinal = "1st";
break;
case 2:
dayOfWeekString = "Monday";
ordinal = "2nd";
break;
case 3:
dayOfWeekString = "Tuesday";
ordinal = "3rd";
break;
case 4:
dayOfWeekString = "Wednesday";
ordinal = "4th";
break;
case 5:
dayOfWeekString = "Thursday";
ordinal = "5th";
break;
case 6:
dayOfWeekString = "Friday";
ordinal = "6th";
break;
case 7:
dayOfWeekString = "Saturday";
ordinal = "7th";
break;
}
if (dayOfWeekInt > 7)
System.out.println("That number is too high.");
else
System.out.println(dayOfWeekString + " is the " + ordinal + " day of the week.");
}
}