where do i put the return statement in the method | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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); } } }

5th Apr 2022, 9:33 PM
Raja Velu
Raja Velu - avatar
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; */ } }
5th Apr 2022, 9:59 PM
Jayakrishna 🇮🇳
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));
6th Apr 2022, 7:21 AM
Nick