Although logically speaking that method will always return something, the compiler cannot check it. The compiler does not check the logic inside the if-statements, only the syntax. Therefore, for the compiler it's possible that all three guards (n > 0, n ==0 and n < 0) are all false (we know better*), and nothing will be returned.

Drop the guard from your last if-statement:

* Actually there are two (non-int) values for which this is actually the case: Float.NaN and Double.NaN.

public static int sign(int n){
if(n>0) return 1;
else if(n==0) return 0;
else return -1;
}
}
In the above method the final return in else block is mandotory, as Java is a strongly typed language, it expects the function to return the value, either from the else block or a seperate return statement.