-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSwitchCase.java
More file actions
37 lines (28 loc) · 986 Bytes
/
SwitchCase.java
File metadata and controls
37 lines (28 loc) · 986 Bytes
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
package example.oo.main;
import java.util.Date;
public class SwitchCase {
public static void main(String args[]){
Date dt= new Date();
dt=new Date(2021,03,12,3,30); //Date(int year, int month, int date, int hrs, int min)
byte period=0;//1- morgen, 2- afternoon, 3-evening
if(dt.getHours()>=5 && dt.getHours()<12) period=1;
if(dt.getHours()>=12 && dt.getHours()<18) period=2;
if(dt.getHours()>=18) period=3;
switch(period){
case 1:
printMessage("Good morning");
break;
case 2:
printMessage("Good afternoon");
break;
case 3:
printMessage("Good evening");
break;
default:
printMessage("zzz...");
}
}
public static void printMessage(String message){
System.out.println( message);
}
}