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
89 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
Evaluate the expression when x is 4:
x += x++ * ++x % 2;