-
Notifications
You must be signed in to change notification settings - Fork 1
/
if_else_prolem.dart
95 lines (75 loc) · 1.77 KB
/
if_else_prolem.dart
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
void main() {
// ************* Problem # 1 *************
// Positive/Negative/Zero Checker
int num = -8;
if (num > 0) {
print("Number is Positive .");
} else if (num < 0) {
print("Number is Negative .");
} else {
print("Number is Zero.");
}
// ************* Problem # 2 *************
// Maximum of Three Numbers
int num1 = 5;
int num2 = 15;
int num3 = 10;
if (num1 >= num2 && num1 >= num3) {
print("Maximum num is $num1");
} else if (num2 >= num1 && num2 >= num3) {
print("Maximum num is $num2");
} else {
print("Maximum number is $num3");
}
// ************* Problem # 3 *************
// Odd or Even
int user_num = 6;
if (user_num % 2 == 0) {
print("Num is Even.");
} else {
print("Num is odd.");
}
// ************* Problem # 4 *************
// Grade Evaluation
String grade = "B";
switch (grade) {
case 'A':
print('Excellent!');
break; // Break statement is optional in dart 3.0
case 'B':
print('Good job!');
case 'C':
print('Satisfactory.');
case 'D':
print('You need improvement.');
case 'F':
print('Sorry, you failed.');
default:
print('Invalid grade entered.');
}
// ************* Problem # 5 *************
// Month Days
String month = "January";
switch (month) {
case 'January':
case 'March':
case 'May':
case 'July':
case 'August':
case 'October':
case 'December':
print('31 days in $month.');
break;
case 'April':
case 'June':
case 'September':
case 'November':
print('30 days in $month.');
break;
case 'February':
print('28 or 29 days in $month.');
break;
default:
print('Invalid month entered.');
}
}