Can you invoke the printMax method in Listing 1 using the following statements?
printMax(1, 2, 2, 1, 4);
printMax(new double[]{1, 2, 3});
printMax(new int[]{1, 2, 3});
LISTING 1 VarArgsDemo.java
1 public class VarArgsDemo {
2 public static void main(String[] args) {
3 printMax(34, 3, 3, 2, 56.5);
4 printMax(new double[]{1, 2, 3});
5 }
6
7 public static void printMax(double... numbers) {
8 if (numbers.length == 0) {
9 System.out.println("No argument passed");
10 return;
11 }
12
13 double result = numbers[0];
14
15 for (int i = 1; i
16 if (numbers[i] > result)
17 result = numbers[i];
18
19 System.out.println("The max value is " + result);
20 }
21 }
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.