Repository navigation
Expand file tree
/
Copy pathConditional_statement.java
More file actions
71 lines (62 loc) · 1.85 KB
/
Copy pathConditional_statement.java
File metadata and controls
71 lines (62 loc) · 1.85 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.util.Scanner;
public class Conditional_statement {
public static void main(String[] args) {
//if-else
//-----------------------------------------------------------
int a = 30;
int b = 40;
if(a<50 && b<50){
System.out.println("both less than 50");
}
else if(a<50 || b<50){
System.out.println("atleast one less than 50");
}
boolean isAdult = true;
if(isAdult != true){
System.out.println("not adult");
}
else{
System.out.println("is adult");
}
if(isAdult){
System.out.println("adult");
}
else{
System.out.println("not adult");
}
if(!isAdult){
System.out.println("not adult");
}
else{
System.out.println("adult");
}
Scanner sc = new Scanner(System.in);
//pen = 10 , notebook = 40
int cash = sc.nextInt();
if(cash<10){
System.out.println("Cannot buy anything");
System.out.println("get more cash");
}
else if(cash>10 && cash<50){
System.out.println("can get 1 thing");
}
else{
System.out.println("can buy both");
}
//switch
//---------------------------------------------------------------------------------
int day = 1;
switch(day){
//all case will be printed if we want to print one than we have to use break;
//if nothing is true default will be printed;
case 1:
System.out.println("monday");
break;
case 2:
System.out.println("tuesday");
break;
default:
System.out.println("wed - sun");
}
}
}