-
-
Save 0ryant/d237cf56e98846576651580d3d22efc4 to your computer and use it in GitHub Desktop.
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"); | |
} | |
} | |
} |
Wrong program
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);
}
}
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");
}
}
}
im a beginner can someone comment on my model , anyway both are similar af :)
public static void printYearsAndDays(long minutes){ if (minutes<0){ System.out.println("invalid value"); }else { int years = (int)minutes/525600; int days= (int) ( (minutes/1440)-(years*365)); System.out.println(years+" years " +days+ " days "); } }