Java Tutorial
In java programming, this program is used to accept the number of days as user input and convert it into number of years, number of months and remaining number of days.
Displays the result as years, months and days once converted into years.
import java.util.Scanner; public class DaysToYear { public static void main(String[] args){ Scanner sc = new Scanner(System.in); System.out.println("Convert Days to Number of Years"); System.out.println("--------------------------------"); int balance, years, months, days; System.out.print("Enter total days: "); int numberOfDays = sc.nextInt(); years = numberOfDays / 365; balance = numberOfDays % 365; months = balance / 30; days = balance % 30; System.out.println("In years"); System.out.println("----------"); System.out.println("Number of years: " + years); System.out.println("Number of months: " + months); System.out.println("Number of days: " + days); } }Output:
D:\Java_Programs>javac DaysToYear.java D:\Java_Programs>java DaysToYear Convert Days to Number of Years -------------------------------- Enter total days: 540 In years ---------- Number of years: 1 Number of months: 5 Number of days: 25 D:\Java_Programs>javac DaysToYear.java D:\Java_Programs>java DaysToYear Convert Days to Number of Years -------------------------------- Enter total days: 2513 In years ---------- Number of years: 6 Number of months: 10 Number of days: 23
Java Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page