Sorry for not posting the complete issue. If I write the below simple piece of code. It gets compiled and work fine
public class TestReturn {
/**
* @param args
*/
public static void main(
String[] args) {
// TODO Auto-generated method stub
System.out.println(sign(1));
}
public static int sign(int n){
if(n>0) return 1;
else if(n==0) return 0;
else return -1;
}
}
BUT if I change this to the below code
public class TestReturn {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(sign(1));
}
public static int sign(int n){
if(n>0) return 1;
else if(n==0) return 0;
else
if(n<0) return -1;
}
}
... then I get the compilation error that "This methods must return of result of the type int".
LOGICALLY both piece of code looks fine.
- Faraz