Computer Science, asked by Aishwary1604, 5 months ago

Write a java program to enter total number of days and convert it into years, months, week and remaining days. Where 1year= 300 days and 1 month= 20 days 1 week= 7 days.​

Answers

Answered by ashokkumarchaurasia
6

Explanation:

/**

* Java program to convert days to years weeks and days.

*/

import java.util.Scanner;

public class DaysConverter {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

/* Input number of days from user */

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

int days = in.nextInt();

/* Year, weeks and days conversion */

int years = (days / 365);

int weeks = (days % 365) / 7;

days = (days % 365) % 7;

/* Print total years, weeks and remaining days in given days */

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

System.out.println("Week/s = " + weeks);

System.out.println("Day/s = " + days);

}

}

Output

Enter days: 373

Year/s = 1

Week/s = 1

Day/s = 1

Answered by Shivu516
2

Answer: Why change the value of year month and days? Still if you want to change then just enter your value instead of the real value in the program.

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 days

Enter days: 1234

Year/s : 3

Month/s : 4

Day/s : 19

Similar questions