#method
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
it requires you to define the method "public static int daysInFeb(int userYear)" at the end
Maybe they will use your method that you write and provide the output formatted string.
ive tried to return only the int but it only worked for 2 of the 5 tests
it failed the unit tests
Did you apply the proper leap year rules?
So your answer is wrong for that part then
what's your implementation?
import java.util.Scanner;
public class LabProgram {
/* Define your method here */
public static String daysInFeb(int userYear){
String result;
boolean isLeap;
if(userYear % 4 == 0 ){
isLeap = true;
}
else if(userYear % 100 ==0 && userYear % 400 == 0){
isLeap = true;
}
else {
isLeap = false;
}
if(isLeap){
result = userYear + " has 29 days in February." ;
}
else{
result = userYear + " has 28 days in February.";
}
return result;
}
public static void main(String[] args) {
/* Type your code here. */
Scanner scnr = new Scanner(System.in);
int year = scnr.nextInt();
System.out.println(daysInFeb(year));
}
}
Does is say on which input it fails?
heres what ive used
it does
it works for the first one
your logic is already wrong. It says 1700 is a leap year
oh
Your method signature is wrong
I recommend rereading the leap year rules.
and it expects the number of days, not the String you're returning based upon the exception