-
Language
Java using JOptionPane
-
Description
Age calculation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import javax.swing.JOptionPane;
public class AgeCalculation {
public static void main (String[] args) {
int age, birth_day, birth_month, birth_year, current_day;
int current_month, current_year;
birth_day = Integer.parseInt(JOptionPane.showInputDialog("Enter the value of birth day"));
birth_month = Integer.parseInt(JOptionPane.showInputDialog("Enter the value of birth month"));
birth_year = Integer.parseInt(JOptionPane.showInputDialog("Enter the value of birth year"));
current_day = Integer.parseInt(JOptionPane.showInputDialog("Enter the value of current day"));
current_month = Integer.parseInt(JOptionPane.showInputDialog("Enter the value of current month"));
current_year = Integer.parseInt(JOptionPane.showInputDialog("Enter the value of current year"));
age=current_year-birth_year;
if(birth_month>current_month||(birth_month==current_month&&birth_day>current_day))
age=age-1;
JOptionPane.showMessageDialog(null,
"Value of age: " + age);
}
}
public class AgeCalculation {
public static void main (String[] args) {
int age, birth_day, birth_month, birth_year, current_day;
int current_month, current_year;
birth_day = Integer.parseInt(JOptionPane.showInputDialog("Enter the value of birth day"));
birth_month = Integer.parseInt(JOptionPane.showInputDialog("Enter the value of birth month"));
birth_year = Integer.parseInt(JOptionPane.showInputDialog("Enter the value of birth year"));
current_day = Integer.parseInt(JOptionPane.showInputDialog("Enter the value of current day"));
current_month = Integer.parseInt(JOptionPane.showInputDialog("Enter the value of current month"));
current_year = Integer.parseInt(JOptionPane.showInputDialog("Enter the value of current year"));
age=current_year-birth_year;
if(birth_month>current_month||(birth_month==current_month&&birth_day>current_day))
age=age-1;
JOptionPane.showMessageDialog(null,
"Value of age: " + age);
}
}