-
Notifications
You must be signed in to change notification settings - Fork 0
/
17-age-group
40 lines (37 loc) · 839 Bytes
/
17-age-group
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
public String ageGroup(Integer n) {
//code here
/* sol1
Integer nn = n;
if(nn>=0 && nn<=1) {
return 'Infant';
} else if (nn>=2 && nn<=14) {
return 'Child';
} else if (nn>=15 && nn<=21) {
return 'Youth';
} else if (nn>=22) {
return 'Adult';
} else {
return 'error';
} */
/* sol 2
if (n>=0 && n<=1) {
return 'Infant';
} else if (n>=2 && n<=14) {
return 'Child';
} else if (n>=15 && n<=21) {
return 'Youth';
} else if (n>=22) {
return 'Adult';
} else {
return 'error';
} */
// sol 3
Integer age = n;
if(age >= 22)
return 'Adult';
else if(age >= 15 && age < 22)
return 'Youth';
else if(age >= 2 && age < 15 )
return 'Child';
return 'Infant';
}