-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFreakyCode.java
More file actions
41 lines (35 loc) · 1.09 KB
/
FreakyCode.java
File metadata and controls
41 lines (35 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.Scanner;
import java.util.InputMismatchException;
public class FreakyCode
{
public static void main(String[] args)
{
boolean stat = false;
double sleepingHours = 0;
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Enter your sleeping time in hours! Daddy loves you~");
try {
sleepingHours = scanner.nextDouble();
break; // Exit the loop if input is valid
} catch (InputMismatchException e) {
System.out.println("Mischievous behavior will lead to punishments!");
scanner.next(); // Clear the invalid input
}
}
scanner.close();
if (sleepingHours >= 8.0) {
stat = true;
} else {
stat = false;
}
if (stat == false) {
System.out.printf("Aww naughty boy, you only slept for ");
System.out.print(sleepingHours);
System.out.println(" hours.");
System.out.print("Get back to your bed and resume sleeping till exceeding 8 hours.");
} else {
System.out.printf("That's daddy's good boy. Let's play! :)");
}
}
}