0
Can anybody explain how program understands the values of a and b?
public static void main(String[ ] args) { int res = max(7, 42); System.out.println(res); //42 } static int max(int a, int b) { if(a > b) { return a; } else { return b; } } Is it because we used STRING at the beginning?
2 Answers
+ 2
max is a function which returns the larger value among variables a and b. On the second line, you just passed values 7 and 42 as arguments to function max, both values are evaluated and 42 is found to be larger, so 42 is returned.
Is my explanation enough or is there more to your query?
0
if you call max(7, 42) method max does a=7, b=42 and then count with it