Computer Science, asked by Masarrat1, 1 year ago

write a program in Java to enter the number of the days and display into the years months and days

Answers

Answered by ajaykrish
0
#include
#include
int main ()
{
int day, y, m;/*day for day input & output,
y for calculate year,
m for calculate month
printf ("Enter the number of days :");
scanf ("%d",&day);
y=day/365; //caluclate years
day%=365; // caluclate remaining days
m=day/30; //caluclate months
day%=30; //caluclate remaining days
printf ("% d years,% months, % d days", y, m, day);
getch ();
return 0;
} output:
enter number of d as usual :1025
2years,9 months,25 days
Answered by Shivu516
0

Answer:

import java.util.Scanner;

public class DaysConverter {

   public static void main (String [] args) {

       Scanner sc = new Scanner(System.in);

       //Taking input from the user

       System.out.println("Here, a month is considered to have 30 day");

       System.out.print("Enter days: ");

       int days = sc.nextInt();

       

       //Most important part comes here

       int years = days/365;

       int months = (days % 365) / 30;

       int Days = (days % 365) % 30;

                       

       //Printing the output

       System.out.println("Year/s : " + years);

       System.out.println("Month/s : " + months);

       System.out.println("Day/s : " + Days);

   }

}

Output:

Here, a month is considered to have 30 day

Enter days: 1234

Year/s : 3

Month/s : 4

Day/s : 19

Similar questions