Page 1 of 1

Hello, can someone help me writing a public method in the class Test below that has the signature printMax(int, int) and

Posted: Fri Jun 10, 2022 11:58 am
by correctanswer
Hello,
can someone help me writing a public method in the class
Test below that has the signature printMax(int, int) and does
not return any value please? The parameters indicate indexes into
the nums array.

The method prints out the largest integer found in the
nums array from the element indexed by the first parameter
through to the element indexed by the second parameter.
The output is of the form
Max is n
where n is the largest element found.
You do not have to perform any checks on the parameters to see
whether they are in bounds for the array.
For example:
TestResult
Test t = new Test(new int[]{8,8,1,8,7,9,5});
t.printMax(0,0);
Max is 8
Test t = new Test(new int[]{9,10,7,15}); t.printMax(0,2);
Max is 10
Here is my code so far:
public class Test
{
private int[] nums;

public Test(int[] vals)
{
nums = vals;
}

// Write your printMax(int, int) method
here

}