-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaifelse.java
More file actions
49 lines (43 loc) · 863 Bytes
/
Javaifelse.java
File metadata and controls
49 lines (43 loc) · 863 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
38
39
40
41
42
43
44
45
46
47
48
49
package basics;
import java.util.*;
public class Javaifelse {
public static void main(String[] args) {
// TODO Auto-generated method stub
//if
if(10>5)
{
System.out.println("10 is greater than 5");
}
//if-else
int time=20;
if(time<18)
{
System.out.println("Good Day");
}
else
{
System.out.println("good evening");
}
//else if statement
Scanner in = new Scanner(System.in);
System.out.println("enter time");
int time1=in.nextInt();
if(time1<10)
{
System.out.println("Good Morning");
}
else if(time1<20)
{
System.out.println("Good Day");
}
else
{
System.out.println("Good Evening");
}
//short hand if else
//ternary operator
String result=(time1<18)?"Good Day":"Good Evening";
System.out.println(result);
in.close();
}
}