Answer:
Explanation:
The following code is written in Java, it creates and tests the findMax() method with the test inputs provided in the question. The method loops through asking the user for inputs, if a positive number is passed it checks if it is larger than the previous numbers and if so, saves it in a variable called max. Otherwise it breaks the loop and returns the variable max. The test output can be seen in the attached picture below.
import java.util.Scanner;
class Brainly {
public static void main(String[] args) {
System.out.println("Max number is: " + findMax());
}
public static int findMax() {
int max = 0;
Scanner in = new Scanner(System.in);
while (true) {
System.out.println("Enter a number: ");
int num = in.nextInt();
if (num >= 0) {
if (num > max) {
max = num;
}
} else {
break;
}
}
return max;
}
}