-
Notifications
You must be signed in to change notification settings - Fork 768
Expand file tree
/
Copy pathCount_Age.java
More file actions
28 lines (21 loc) · 843 Bytes
/
Count_Age.java
File metadata and controls
28 lines (21 loc) · 843 Bytes
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
import java.util.Scanner;
public class Count_Age{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.println("Please enter your birth year(YYYY) :");
int birth_year = in.nextInt();
System.out.println("Please enter your birth month(MM) :");
int birth_month = in.nextInt();
System.out.println("Please enter current year(YYYY) :");
int current_year = in.nextInt();
System.out.println("Please enter current month(MM) :");
int current_month = in.nextInt();
int year = current_year - birth_year;
int month = current_month - birth_month;
if(month<0){
year--;
month+=12;
}
System.out.println("Your age is " + year + " years and " + month + " months.");
}
}