Computer Applications
Write a program in Java to accept the number of days and display it after converting it into number of years, month & days.
Sample Input:
Enter the day number: 415
Sample Output:
1 Years 1 Months 20 Days
Java
Java Operators
86 Likes
Answer
import java.util.Scanner;
public class KboatDayConversion
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter days: ");
int days = in.nextInt();
int years = days / 365;
days = days - (365 * years);
int months = days / 30;
int d = days - (months * 30);
System.out.println(years + " Years " + months + " Months " + d + " Days");
}
}
Output

Answered By
35 Likes
Related Questions
What will be the output of the following code?
int x = 9; x -= 2 * --x / x++ % 3; System.out.println("x = " + x);
Rewrite the following program segment using logical operators:
if(x > 5) if(x > y) System.out.println(x + y);
Evaluate the expression when x is 4:
x += x++ * ++x % 2;
Identify the operator that gets the highest precedence while evaluating the given expression:
x + y * z / w - p