Can anybody explain how program understands the values of a and b? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
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?

24th Aug 2019, 11:21 AM
Andrew
Andrew - avatar
2 ответов
+ 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?
24th Aug 2019, 11:24 AM
Hatsy Rei
Hatsy Rei - avatar
0
if you call max(7, 42) method max does a=7, b=42 and then count with it
24th Aug 2019, 11:23 PM
zemiak