#method

1 messages · Page 1 of 1 (latest)

plucky sleet
#

i really dont get this one.
Its a static int method yet it asks you to return both and int and a string ?

foggy valeBOT
#

<@&987246399047479336> please have a look, thanks.

plucky sleet
#

it requires you to define the method "public static int daysInFeb(int userYear)" at the end

nimble fractal
#

Maybe they will use your method that you write and provide the output formatted string.

plucky sleet
#

it failed the unit tests

rigid rain
#

Did you apply the proper leap year rules?

nimble fractal
#

So your answer is wrong for that part then

rigid rain
#

what's your implementation?

plucky sleet
#

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));
}
}

nimble fractal
#

Does is say on which input it fails?

plucky sleet
#

heres what ive used

plucky sleet
#

it works for the first one

rigid rain
#

your logic is already wrong. It says 1700 is a leap year

plucky sleet
#

oh

nimble fractal
#

Your method signature is wrong

rigid rain
#

I recommend rereading the leap year rules.

#

and it expects the number of days, not the String you're returning based upon the exception

plucky sleet
#

ohhh

#

ok

#

returning only the numbers of days are good

#

ill recheck the leap year rules

#

tysm ❤️

plucky sleet
#

yipee

#

its done

#

thanks

#

should i just delete this thread ?