Arguments are evaluated left to right
Each argument is fully evaluated, in order, before add3 starts.
Parameters let a method receive input values, and a return value lets it hand one result back to the caller. Together they turn a method into a reusable little machine: values go in, work happens, a result comes out.
Change the code and press Run (Ctrl+Enter). Try to predict the output first, then break it on purpose and read the error. Your edits are saved and match the lesson page.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write static double celsiusToFahrenheit(double c) (F = C x 9 / 5 + 32) and print the result for 0, 37 and 100.
Write static boolean isLeapYear(int year) (divisible by 4, except centuries, unless divisible by 400) and test 1900, 2000, 2024 and 2023.
Write static int countVowels(String s) that returns how many of a e i o u (lower case) the string contains, and test it on "programming".
Explain it without notes
What is the difference between a parameter and an argument? Use one example call to show both.
Why does missing return statement appear even when you know the condition is always true at run time?
In what order are method arguments evaluated in Java, and why does it matter?
How would you return both the minimum and maximum of three numbers from one method?
Expected output
evaluating first
evaluating second
evaluating third
inside add3
sum = 6
inside add3
i++ twice: 3
i is now 3