Menu
Question Index
...

What will be the output of the following program?

public class HelloWorld {
    int calculate(int[]... vars) {
        int sum = 0, b, c;
        for (b = 0; b < vars.length; b++) {
            for (c = 0; c < vars[b].length; c++) {
                sum += vars[b][c];
            }
        }
        return (sum);
    }
    public static void main(String args[]) {
        HelloWorld values = new HelloWorld();
        int sum = 0;
        sum = values.calculate(new int[]{10, 20, 30, 40}, new int[]{40, 50, 60});
        System.out.println("The sum of the numbers is:" + sum);
    }
}


The sum of the numbers is:25
The sum of the numbers is:100
The sum of the numbers is:250
Compilation Error due to invalid declaration of integer variable as arguments.
Compilation Error or Runtime Error for some other reason.

Doubts

Problems

Topic: Unknown

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App