This exercise's objective is to familiarize you with the use of methods in Java.
You will write a few methods in this lab. After writing them all, show your results to the instructor.
After launching the Eclipse IDE, create a new project and name it Lab4. Create a class within this project called LabExercise4. In the pop-up window for specifying the name of this class, do not click on the check-box next to the option for creating the main method. Within this class, do the following tasks.
public static int max(int num1, int num2) {
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
}
Note the name of the method, its parameters and its return value. The proper
way of invoking this method from within another method is:
int z = max(x, y);
public static void main(String args[]) {
int max = 0;
findmax(1, 2, max);
System.out.println("max = " + max);
}
public static void findmax(int num1, int num2, int max) {
if (num1 < num2)
max = num2;
else
max = num1;
}
Write down the output that this program produces after running it. What value
did you expect? What value did the program actually produce? The reason for the
answer that you see is the pass-by-value mechanism of parameter passing that is
employed by Java. Show the result of running the program to the instructor.