You can make this better by using the "%" on the input, if it return 0 then the number is Even, otherwise it is odd.
But I think you know this already :)
class EvenOrOdd { public static String evenOrOdd(int input) { if (input%2==0){ return "Even"; } return "Odd"; } }
- class EvenOrOdd {
- public static String evenOrOdd(int input) {
if (input==0){- if (input%2==0){
- return "Even";
} else if (input==1){return "Odd";} return evenOrOdd(input-2);- }
- return "Odd";
- }
- }