Write a program that inputs age in days and calculate age in months and years.

 

public static void main(String[] args) {

Scanner n=new Scanner(System.in);

int d,m,y,w;

System.out.println(“Enter age=”);

d= n.nextInt();

y=d/365;

d=d%365;

m=d/30;

d=d%30;

System.out.println(“months are=”+m);

System.out.println(“Year  are=”+y);

}

}

Output

run:
Enter age=
12
months are=0
Year are=0
BUILD SUCCESSFUL (total time: 12 seconds)

Leave a Reply

Your email address will not be published. Required fields are marked *