I\'m very new to Java. Eclipse is giving me the error
The method must return a result of type int
for the following code:
public class firstprog {
public static int largest(int a,int b,int c)
{
if(a>b)
{
if(a>c)
{
return a;
}
else if(b>c)
{
return b;
}
else
{
return c;
}
}
return 0;
}
public static void main(String args[]) {
int a=7;
int b=8;
int c=9;
System.out.println(largest(a,b,c));
}
}
Note: you have to add return statement, because a is not greater then b, so it it not going inside of if block.. In your larget(...) it is expecting return statement as int.. so you have to add one more return statement. then it work ... Cheers ...!!!