I got an assignment need to do the following: If the input is even, return 0. Otherwise, returns the factorial of the integer input, but without multiplying any even numbers. and i wrote down some quote but it run with error. Can someone tell me where i did wrong?
public static int oddFactorial(int number){
if (number%2==0)
return (0);
else{
int counter = 1;
int toReturn= 1;
while (counter <= number)
toReturn = toReturn*counter;
counter+=2;
return number;
}
}
public static void main(String[] args) {
int number = 7;
}
}
This is what you need to do. Check the highlighted line.You are calling oddFactorial
method and displaying its result. The order of oddFactorial
and main doesn't matter you need to call the method from main
.
public static int oddFactorial(int number){
if (number%2==0){
return (0);}
int counter = 1;
int toReturn= 1;
while (counter <= number){
toReturn = toReturn*counter;
counter+=2;
}
return toReturn;
}
public static void main(String[] args) {
int number = 7;
**System.out.println(oddFactorial(number));**
}
}