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
A student executes the following code to increase the value of a variable ‘x’ by 2.
He has written the following statement, which is incorrect.
x = +2;
What will be the correct statement?
A. x +=2;
B. x =2;
C. x = x +2;- Only A
- Only C
- All the three
- Both A and C
What will be the output of the following code?
int x = 9; x -= 2 * --x / x++ % 3; System.out.println("x = " + x);
A student needs to calculate the average of three numbers
x
,y
, andz
. Which is the correct Java expression for this calculation?Identify the operator that gets the highest precedence while evaluating the given expression:
x + y * z / w - p