MINUTES TO YEAR AND DAYS CHALLENGE

 Write a method printYearsAndDays with parameters of type long named minutes.
The method should not return anything and it needs to calculate years and days from the minutes parameter.
If the parameter is less than 0, print text "INVALID VALUE". Otherwise, print in the format 
"XX min = YY y and ZZ d".
Soln  
    package com.cnc;
    public class Main {

public static void main(String[] args) {
printYearsAndDays(525600);
}
public static void printYearsAndDays(long minutes){
if(minutes<0){
System.out.println("Invalid Value");
}else {
long years = minutes/(60*24*365);
long days = minutes/(24*60);
long remainingDays = days%365;
System.out.println(minutes+" min ="+" "+years +" y and "+remainingDays+" d");
}
}
}

Popular posts from this blog

NUMBER PALINDROME CHALLENGE

ENCAPSULATION CHALLENGE

LARGEST PRIME FACTOR OF A NUMBER