views:

80

answers:

3

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?

+1  A: 

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

o.k.w
re int: it will be an int already.
pstanton
+1  A: 
if (x%2==0){
      return x/2;

change to:

if (x%2==0){
      return x/2;
}
dcp
+5  A: 

your problem is mismatched braces:

static int syracuse(int x){
    if (x%2==0){
      return x/2;
    } else {
      return 3*x+1;
    }
}
ninesided