Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class AgeCalculation
- {
- public static void main(String[] args)
- {
- String takeBirthDay = JOptionPane.showInputDialog("Enter Birthday(dd): ");
- String takeBirthMonth = JOptionPane.showInputDialog("Enter Birth Month(mm): ");
- String takeBirthYear = JOptionPane.showInputDialog("Enter Birth Year(yyyy): ");
- String takePresentDay = JOptionPane.showInputDialog("Enter Present day(dd): ");
- String takePresentMonth = JOptionPane.showInputDialog("Enter Present Month(mm): ");
- String takePresentYear = JOptionPane.showInputDialog("Enter Present Year(yyyy): ");
- int BirthDay = Integer.parseInt(takeBirthDay);
- int BirthMonth = Integer.parseInt(takeBirthMonth);
- int BirthYear = Integer.parseInt(takeBirthYear);
- int PresentDay = Integer.parseInt(takePresentDay);
- int PresentMonth = Integer.parseInt(takePresentMonth);
- int PresentYear = Integer.parseInt(takePresentYear);
- int month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- if (BirthDay > PresentDay)
- {
- PresentDay = PresentDay + month[BirthMonth - 1];
- PresentMonth = PresentMonth - 1;
- }
- if (BirthMonth > PresentMonth)
- {
- PresentYear = PresentYear - 1;
- PresentMonth = PresentMonth + 12;
- }
- int calculated_date = PresentDay - BirthDay;
- int calculated_month = PresentMonth - BirthMonth;
- int calculated_year = PresentYear - BirthYear;
- JOptionPane.showMessageDialog(null,"Your age is "+ calculated_date +" days, "+ calculated_month +" months and "+ calculated_year +" years.", "Result", JOptionPane.PLAIN_MESSAGE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement