Menu
Topics Index
...
`

passing array as parameter


If you need explanation Read this topic

If you need Answer Take test on this topic

passing array as parameter
What will be the output of the following program?
public class GoodMorning {
    public static void main(String args[]) {
        printMax(34, 3, 3, 2, 56.5);
        printMax(new double[]{1, 2, 3});
    }
    public static void printMax(double... numbers) {
        if (numbers.length == 0)
            return;
        double result = numbers[0];
        for (int i = 1; i < numbers.length; i++)
            if (numbers[i] > result)
                result = numbers[i];
        System.out.println("The max value is " + result);
    }
}

A. The max value is 56.5
The max value is 56.5
B. The max value is 56
The max value is 3
C. The max value is 2
The max value is 1
D. Some other output
E. Compilation Error or Runtime Error
Topic: Unknown

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

answer is D since the result will be "The max value is 56.5

Posted by Sireesha Sanku    2014-05-01 06:28:43


The max value is 3.0"

Posted by Sireesha Sanku    2014-05-01 06:28:55


ans is D just it prints the Max value from both the inputs..so output looks like The Max Value is 56.5 \n The Max value is 3.0

Posted by Nagendra Reddy    2014-05-01 06:41:54


Congratulations Nagendra Reddy. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-05-02 04:11:57


© meritcampus 2019

All Rights Reserved.

Open In App