Write a program that asks for your age in years, months, and days and writes out your age in seconds. Do this by calculating the number of total
days you have been alive, then multiply this by the number of hours per day (24), the number of minutes per hour (60), and the number of seconds
per minute (60). Assume that there are 365 days per year (ignore leap years). But correctly take account of the different number of days in different
months. If the user enters 5 for the number of months, add up the number of days in the first 5 months: 31 + 28 + 31 + 30 + 31
A human lifespan is about 2.5 billion seconds (2.5 billion heart-beats).


These are my codes: not sure bout my used formula..

import java.util.Scanner;
public class DMExer7 {
public static void main (String [] args) {
Scanner scan = new Scanner (System.in);

System.out.print( "Enter age in years: ");
int ageY = scan.nextInt();
System.out.print( "plus how many months: ");
int ageM = scan.nextInt();

int ageS = (((ageY *24)*60)*60);
int ageS1 = ageS + (31*24*60*60);
int ageS2 = ageS + (28*24*60*60) +(31*24*60*60);
int ageS3 = ageS + (31*24*60*60)+(28*24*60*60) +(31*24*60*60);
int ageS4 = ageS + (30*24*60*60)+ (31*24*60*60)+(28*24*60*60) +(31*24*60*60);
int ageS5 = ageS + (31*24*60*60)+ (30*24*60*60)+ (31*24*60*60)+(28*24*60*60*60) +(31*24*60*60);
int ageS6 = ageS + (30*24*60*60)+ (31*24*60*60)+ (30*24*60*60)+ (31*24*60*60)+(28*24*60*60) +(31*24*60*60);
int ageS7 = ageS + (31*24*60*60)+ (30*24*60*60)+ (31*24*60*60)+ (30*24*60*60)+ (31*24*60*60)+(28*24*60*60) +(31*24*60*60);
int  ageS8 = ageS + (31*24*60*60)+ (31*24*60*60)+ (30*24*60*60)+ (31*24*60*60)+ (30*24*60*60)+ (31*24*60*60)+(28*24*60*60) +(31*24*60*60);
int  ageS9 = ageS + (31*24*60*60)+ (31*24*60*60)+ (31*24*60*60)+ (30*24*60*60)+ (31*24*60*60)+ (30*24*60*60)+ (31*24*60*60)+(28*24*60*60) +(31*24*60*60);
int  ageS10 = ageS + (31*24*60*60)+ (31*24*60*60)+ (31*24*60*60)+ (31*24*60*60)+ (30*24*60*60)+ (31*24*60*60)+ (30*24*60*60)+ (31*24*60*60)+(28*24*60*60) +(31*24*60*60);
int  ageS11 = ageS + (30*24*60*60)+ (31*24*60*60)+ (31*24*60*60)+ (31*24*60*60)+ (31*24*60*60)+ (30*24*60*60)+ (31*24*60*60)+ (30*24*60*60)+ (31*24*60*60)+(28*24*60*60) +(31*24*60*60);
int  ageS12 = ageS + (31*24*60*60)+(30*24*60*60)+ (31*24*60*60)+ (31*24*60*60)+ (31*24*60*60)+ (31*24*60*60)+ (30*24*60*60)+ (31*24*60*60)+ (30*24*60*60)+ (31*24*60*60)+(28*24*60*60*60) +(31*24*60*60);

if (ageM == 1){
    System.out.println("Your age in seconds: " + ageS1);
}
if (ageM == 2){
    System.out.println("Your age in seconds: " + ageS2);
}
if (ageM == 3){
   
    System.out.println("Your age in seconds: " + ageS3);
}
if (ageM == 4){
    
    System.out.println("Your age in seconds: " + ageS4);
}
if (ageM == 5){
    
    System.out.println("Your age in seconds: " + ageS5);
}
if (ageM == 6){
  
    System.out.println("Your age in seconds: " + ageS6);
}
if (ageM == 7){
    
    System.out.println("Your age in seconds: " + ageS7);
}
if (ageM == 8){
    
    System.out.println("Your age in seconds: " + ageS8);
}
else if (ageM == 9){
    
    System.out.println("Your age in seconds: " + ageS9);
}
else if (ageM == 10){
    
    System.out.println("Your age in seconds: " + ageS10);
}
else if (ageM == 11){
    
    System.out.println("Your age in seconds: " + ageS11);
}
else if (ageM == 12){
    
    System.out.println("Your age in seconds: " + ageS12);
}
else if (ageM==0){

System.out.println("Your age in seconds: " + ageS);
}
}
}

I''l just want to know if my formulas are correct coz' I dont have any idea what is the specific output must appear

This article has been dead for over six months. Start a new discussion instead.