-
Language
Java using BufferedReader
-
Description
Age calculation
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
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.io.*;
public class AgeCalculation {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int age, birth_day, birth_month, birth_year, current_day;
int current_month, current_year;
System.out.print("Enter the value of birth day: ");
birth_day = Integer.parseInt(in.readLine());
System.out.print("Enter the value of birth month: ");
birth_month = Integer.parseInt(in.readLine());
System.out.print("Enter the value of birth year: ");
birth_year = Integer.parseInt(in.readLine());
System.out.print("Enter the value of current day: ");
current_day = Integer.parseInt(in.readLine());
System.out.print("Enter the value of current month: ");
current_month = Integer.parseInt(in.readLine());
System.out.print("Enter the value of current year: ");
current_year = Integer.parseInt(in.readLine());
age=current_year-birth_year;
if(birth_month>current_month||(birth_month==current_month&&birth_day>current_day))
age=age-1;
System.out.println("Value of age: " + age);
in.close();
}
}
public class AgeCalculation {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int age, birth_day, birth_month, birth_year, current_day;
int current_month, current_year;
System.out.print("Enter the value of birth day: ");
birth_day = Integer.parseInt(in.readLine());
System.out.print("Enter the value of birth month: ");
birth_month = Integer.parseInt(in.readLine());
System.out.print("Enter the value of birth year: ");
birth_year = Integer.parseInt(in.readLine());
System.out.print("Enter the value of current day: ");
current_day = Integer.parseInt(in.readLine());
System.out.print("Enter the value of current month: ");
current_month = Integer.parseInt(in.readLine());
System.out.print("Enter the value of current year: ");
current_year = Integer.parseInt(in.readLine());
age=current_year-birth_year;
if(birth_month>current_month||(birth_month==current_month&&birth_day>current_day))
age=age-1;
System.out.println("Value of age: " + age);
in.close();
}
}