/home/caleb/ASDV-Java/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/Switch3ConvertedToIfElse.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 Switch3ConvertedToIfElse {
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();
if (dayOfWeekInt == 1) {
dayOfWeekString = "Sunday";
ordinal = "1st";
} else if (dayOfWeekInt == 2) {
dayOfWeekString = "Monday";
ordinal = "2nd";
} else if (dayOfWeekInt == 3) {
dayOfWeekString = "Tuesday";
ordinal = "3rd";
} else if (dayOfWeekInt == 4) {
dayOfWeekString = "Wednesday";
ordinal = "4th";
} else if (dayOfWeekInt == 5) {
dayOfWeekString = "Thursday";
ordinal = "5th";
} else if (dayOfWeekInt == 6) {
dayOfWeekString = "Friday";
ordinal = "6th";
} else if (dayOfWeekInt == 7) {
dayOfWeekString = "Saturday";
ordinal = "7th";
}
if (dayOfWeekInt > 7) {
System.out.println("That number is too high.");
} else {
System.out.println(dayOfWeekString + " is the " + ordinal + " day of the week.");
}
}
}