Created
August 6, 2019 11:37
-
-
Save 0ryant/d237cf56e98846576651580d3d22efc4 to your computer and use it in GitHub Desktop.
Java - Coding Challenge 9 - Minutes to Years and Days
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MinutesToYearsDaysCalculator { | |
public static void printYearsAndDays(long minutes){ | |
if (minutes <0) { | |
System.out.println("Invalid Value"); | |
} else { | |
long years = minutes / 525600; | |
long minutesRemaining = (minutes - (years * 525600)); | |
long daysRemaining = minutesRemaining / 1440; | |
System.out.println(minutes + " min = " + years + " y and " + daysRemaining + " d"); | |
} | |
} | |
} |
Sorry I wrote this years ago, if I posted it then it passed the unit tests 😅
public static void printYearsAndDays(long minutes) {
if (minutes < 0) {
System.out.println("invalid Value");
} else {
long days = minutes / 1440;
long years = minutes / 525600;
System.out.println(minutes + " min = " + years + " y and " + days + " d");
}
}
public class MinutesToYearsDaysCalculator {
public static void printYearsAndDays(long minutes){
if (minutes < 0) {
System.out.println("Invalid Value");
}else {
// make to understand process easy, I go step by step
long hour = minutes / 60; //simple find first hours
long day = hour / 24; // then go for days
long year = day / 365; //then find a years
long remaindays= day%365; //then go for remaining days, so, after some years how many days left we will see
System.out.println(minutes + " min = " + year + " y and " + remaindays + " d");
}
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the above program wont work in intellij idea you have to change the void to long and add a return statement if you want it to work
MinutesToYearsDaysCalculator.java
public class MinutesToYearsDaysCalculator {
public static long printYearsAndDays(long minutes) {
if (minutes < 0) {
System.out.println("Invalid Value");
} else {
long years = minutes / 525600;
long minutesRemaining = (minutes - (years * 525600));
long daysRemaining = minutesRemaining / 1440;
System.out.println(minutes + " min = " + years + " y and " + daysRemaining + " d");
}
return minutes;
}
}
main.java
public class main {
public static void main(String[] args) {
long years= MinutesToYearsDaysCalculator.printYearsAndDays(525600);
}
}