Computer Science, asked by mdrishti241, 11 months ago

write a Java program to input number of days and display to result after converting into number of years,months,and remaining days​

Answers

Answered by kantinilesh2312
7

import java.util.Scanner;

public class Year_Week_Day

{

public static void main(String args[])

{

int m, year, week, day;

Scanner s = new Scanner(System.in);

System.out.print("Enter the number of days:");

m = s.nextInt();

year = m / 365;

m = m % 365;

System.out.println("No. of years:"+year);

week = m / 7;

m = m % 7;

System.out.println("No. of weeks:"+week);

day = m;

System.out.println("No. of days:"+day);

}

}

Answered by Shivu516
1

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