-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConditionalStatements2.java
More file actions
210 lines (198 loc) · 7.26 KB
/
ConditionalStatements2.java
File metadata and controls
210 lines (198 loc) · 7.26 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import java.util.Scanner;
public class ConditionalStatements2{
public static void main(String[] args){
Scanner obj = new Scanner(System.in);
long year = obj.nextLong(); // leap year or not
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
System.out.println("Leap year");
} else {
System.out.println("Not a Leap year");
}
int day_num = obj.nextInt(); //print corresponding day
switch(day_num){
case 0:
System.out.println("Sunday");
break;
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
case 4:
System.out.println("Thursday");
break;
case 5:
System.out.println("Friday");
break;
case 6:
System.out.println("Saturday");
break;
default:
System.out.println("Invalid");
break;
}
int month_num = obj.nextInt(); //print the respective month name
switch(month_num){
case 1:
System.out.println("January");
break;
case 2:
System.out.println("February");
break;
case 3:
System.out.println("March");
break;
case 4:
System.out.println("April");
break;
case 5:
System.out.println("May");
break;
case 6:
System.out.println("June");
break;
case 7:
System.out.println("July");
break;
case 8:
System.out.println("August");
break;
case 9:
System.out.println("September");
break;
case 10:
System.out.println("October");
break;
case 11:
System.out.println("November");
break;
case 12:
System.out.println("December");
break;
default:
System.out.println("Invalid");
break;
}
char letter = obj.next().charAt(0); // upper case or lower case or none
if (letter >= 'a' && letter <= 'z') {
System.out.println("LOWERCASE");
} else if (letter >= 'A' && letter <= 'Z') {
System.out.println("UPPERCASE");
} else {
System.out.println("NONE");
}
int salary = obj.nextInt(); //Basic Salary <= 10000 : HRA = 20%, DA=80%
double grossSalary = 0.00; //Basic Salary <= 20000 : HRA = 25%, DA=90%
if(salary<=10000) //Basic Salary > 20000 : HRA = 30%, DA=95%
grossSalary = salary+salary*0.2+salary*0.8;
else if(salary>10000 && salary<=20000)
grossSalary = salary+salary*0.25+salary*0.90;
else if(salary>20000)
grossSalary = salary+salary*0.30+salary*0.95;
System.out.printf("Rs.%.2f",grossSalary);
char ch = obj.next().charAt(0); //alphabet or a number or special character
if (ch >= '0' && ch <= '9') {
System.out.println("NUMBER");
} else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
System.out.println("ALPHABET");
} else {
System.out.println("SPECIAL CHARACTER");
}
int mark = obj.nextInt(); //marks>=91 --> A
switch (mark) { //76<=marks<=90 --> B
case 91: //61<=marks<=75 --> C
case 92: //marks<=60 --> D
case 93:
case 94:
case 95:
case 96:
case 97:
case 98:
case 99:
case 100:
System.out.println("Grade A");
break;
case 76:
case 77:
case 78:
case 79:
case 80:
case 81:
case 82:
case 83:
case 84:
case 85:
case 86:
case 87:
case 88:
case 89:
case 90:
System.out.println("Grade B");
break;
case 61:
case 62:
case 63:
case 64:
case 65:
case 66:
case 67:
case 68:
case 69:
case 70:
case 71:
case 72:
case 73:
case 74:
case 75:
System.out.println("Grade C");
break;
default:
System.out.println("Grade D");
break;
}
int num1 = obj.nextInt(); //Perform the operation with the integer values
char op = obj.next().charAt(0); //based on the character(+,-,*,/)
int num2 = obj.nextInt();
int ans = 0;
switch(op) {
case '+':
ans = num1 + num2;
break;
case '-':
ans = num1 - num2;
break;
case '*':
ans = num1 * num2;
break;
case '/':
ans = num1 / num2;
break;
}
System.out.println(ans);
int number = obj.nextInt(); //electricity bill
double bill; //For First 50 Units Rs.0.50/unit
if (number > 250) { //For next 100 Units Rs.0.75/unit
bill = (50 * 0.50) + (100 * 0.75) + (100 * 1.20) + (number - 250) * 1.50; //For next 150 Units Rs.1.20/unit
} else if (number > 150) { //For unit above 250 Rs.1.50/unit
bill = (50 * 0.50) + (100 * 0.75) + (number - 150) * 1.20; //additional surcharge of 20%
} else if (number > 50) {
bill = (50 * 0.50) + (number - 50) * 0.75;
} else {
bill = number * 0.5;
}
bill = bill + (bill * 0.2);
System.out.printf("%.2f", bill);
long s1 = obj.nextLong(); //whether the given three sides can form a triangle or not.
long s2 = obj.nextLong();
long s3 = obj.nextLong();
if ((s1 + s2) > s3 && (s1 + s3) > s2 && (s2 + s3) > s1) {
System.out.println("Valid");
} else {
System.out.println("Not Valid");
}
}
}