Created
October 23, 2022 20:56
-
-
Save chamellion/ca837421a5b599df4da8868f03311773 to your computer and use it in GitHub Desktop.
CSCM_41 LAB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class LabThree { | |
public static void main(String[] args) { | |
System.out.println("Please enter the hour of the day.. "); | |
System.out.println("Hint.. Please enter hour of day in 24hrs time format i.e 1 - 24..."); | |
Scanner scanner = new Scanner(System.in); | |
if (scanner.hasNextInt()){ | |
int hourOfDay = scanner.nextInt(); | |
if (hourOfDay <= 0 || hourOfDay > 24){ | |
System.out.println("We have 24hrs in a day, Please enter a number between 1 and 24"); | |
main(null); | |
}else { | |
if (hourOfDay >= 5 && hourOfDay <= 12){ | |
System.out.println("We are in the morning... Good morning"); | |
}else if (hourOfDay > 12 && hourOfDay < 18){ | |
System.out.println("It's afternoon.... Good afternoon"); | |
}else { | |
System.out.println("It's evening time. Good evening"); | |
} | |
} | |
}else { | |
System.out.println("Invalid input entered. Please try again..."); | |
main(null); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment