-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculateAges.java
More file actions
74 lines (47 loc) · 2.66 KB
/
CalculateAges.java
File metadata and controls
74 lines (47 loc) · 2.66 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
import java.util.Scanner;
public class CalculateAges {
public static void main(String[] args) {
Scanner user = new Scanner (System.in);
String[] names = new String[3];
byte[] ages = new byte[3];
System.out.println("What is the current year?");
short currentYear = user.nextShort();
System.out.println("Type your name:");
names[0] = user.next();
System.out.println("Now give your age:");
ages[0] = user.nextByte();
System.out.println("Give a second name:");
names[1] = user.next();
System.out.println("Give the age of the second name you gave:");
ages[1] = user.nextByte();
System.out.println("Give the third and last name:");
names[2] = user.next();
System.out.println("And finaly the age of the third person you named:");
ages[2] = user.nextByte();
//Output prints
System.out.println(names[0] +" was born in " + (currentYear - ages[0]));
System.out.println(names[1] +" was born in " + (currentYear - ages[1]));
System.out.println(names[2] +" was born in " + (currentYear - ages[2]));
if (ages[0]<60){
System.out.println("In 1960 "+ names[0] +" was not born yet and in 2040 will be " +
((2040 - currentYear) + ages[0]) + " years old." );
}else{
System.out.println(names[0]+" in 1960 was "+(ages[0]-(currentYear-1960))+" years old " +" and in 2040 will be " +
((2040 - currentYear) + ages[0]) + " years old.");
}
if (ages[1]<60){
System.out.println("In 1960 "+ names[1] +" was not born yet and in 2040 will be " +
((2040 - currentYear) + ages[1]) + " years old." );
}else{
System.out.println(names[1]+" in 1960 was "+(ages[1]-(currentYear-1960))+" years old " +" and in 2040 will be " +
((2040 - currentYear) + ages[1]) + " years old.");
}
if (ages[2]<60){
System.out.println("In 1960 "+ names[2] +" was not born yet and in 2040 will be " +
((2040 - currentYear) + ages[2]) + " years old." );
}else{
System.out.println(names[2]+" in 1960 was "+(ages[2]-(currentYear-1960))+" years old " +" and in 2040 will be " +
((2040 - currentYear) + ages[2]) + " years old.");
}
}
}