Sooo I'm having an issue with my function.
static int syracuse(int x){
if (x%2==0){
return x/2;
else{
return 3*x+1;
}
}
}
Well soo my issue is : if x is even, return x/2 OR is x if odd. returns 3x+1. But when I try to compile java tells me that ( 'else' with 'if') I don't know what to do :\
why would I need a else if?
your problem is mismatched braces:
static int syracuse(int x){
if (x%2==0){
return x/2;
} else {
return 3*x+1;
}
}
Your braces are wrongly placed.
static int syracuse(int x){
if (x%2==0){
return x/2;
}
else{
return 3*x+1;
}
}
PS: I'm not an java expert, so I'm not sure x/2 can be cast as int on return
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With