0
where do i put the return statement in the method
public class Program { public static void main(String[] args) { } static int yes(int a,int b){ if(a>b){ System.out.println(a); } else{ System.out.println(b); } } }
2 Answers
+ 2
public class Program
{
public static void main(String[] args {
yes(10,5);
}
static int yes(int a,int b){
if(a>b){
System.out.println(a);
}
else{
System.out.println(b);
}
return 0; //here Or where ever you need.. For this instead make this void method as you don't need to return anything.. Like
/*
static void yes(int a, int b) {
...
}
//no need return;
*/
}
}
0
You can also do:
if(a>b){
return a;
} else return b;
And later when you actually need to print out the result, you go:
System.out.println(yes(x, y));