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
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
Related Questions
if (a>b&&b>c) then largest number is:
- b
- c
- a
- wrong expression
A store has purchased some cola cans of various brands. It purchased 50 cans @ ₹15 per can, 30 cans @ ₹20 per can and 40 cans @ ₹21 per can. Write a Java program to compute how much amount did the store pay.
Identify the operator that gets the highest precedence while evaluating the given expression:
a + b % c * d - e
- +
- %
- -
- *
Evaluate the expression when x is 4:
x += x++ * ++x % 2;