program to convert days into year month and days
Convert days into year month and days
import java.util.Scanner;public class DateConv{int Totaldays;int year;int monint days;public static void main(System []args){System.out.println("Enter total days to be converted months and days");//Creating anonymous object for the built-in class 'Scanner'int number= new Scanner(System.in).nextInt();if (number>0){DateConv obj= new DateConv();obj.setTotaldays(number); //Calling setTotaldays methodobj.Conv(); //Calling Conv method//Printing resultSystem.out.println(obj.Totaldays+" days = "+obj.year+" year "+obj.month+" month "+obj.days+" days");}elseSystem.out.println("Please Enter valid numbers");}public void setTotaldays(int Totaldays){this.Totaldays=Totaldays;}public int getTotaldays(){return this.Totaldays;}public void Conv(){year= Totaldays/365; //Calculationint rem= Totaldays%365; //declaring and initializing variable remmonth= rem/30; //Calculationdays= rem%30; //Calculation}}
Output of this program is:-
Enter total days to be converted months and days 800 800 days = 2 year 2 month 10 days
Comments
Post a Comment