Topics Index

Array Output795

If you need explanation Read this topic

If you need Answer Take test on this topic

Array Output795
What will be the output of the following program?
class ArrayOutput
    public static void main(String args[])
        int[] input = {3, 5, 6, 7};
        int output = multiplyEveryElement(input);
        System.out.print("Result of multiplying every element = " + output + ".");

    public static int multiplyEveryElement(int[] input)
        int args = 1;
        for(int i = 0; i <= input.length - 1; i++)
            args *= input[i];
        return args;

A. Result of multiplying every element = 210.
B. Result of multiplying every element = 90.
C. Result of multiplying every element = 630.
D. Compilation Error
E. Throws ArrayIndexOutOfBoundsException
Topic: Learn Arrays And Loops

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.

ans is (C).

Posted by Anuj Batham    2015-03-12 03:43:44

here answer is c
excution start from main in we creating an array input with values(3,5,6,7)
we calling method multiplyEvery element with argument as (input) here we calling method without ccreating  object that 's  function must be static and it was their for that method
and in multiplyEvery element method we creating a variable args initialized with  1 . starting a for loop 0 to input.length() and in loop we are mulplied all elemnts in  tharray input
1 iteration(i=0):args*=input[i]=>args=1*3=>args=3;
2 iteration(i=1):args*=input[i]=>args=3*5=>args=15;
3 iteration(i=2):args*=input[i]=>args=15*6=>args=90;
4 iteration(i=3):args*=input[i]=>args=90*7=>args=630;
after completion loop args consisting 630 and we returning that value to main method and that value is printed in main method:
thats why ans is 630 option C.

Posted by Goutham Singarapu    2015-03-12 04:07:44


--Here,the concept of arrays is used.

--First of all array named input is declared and initialized with 4 elements 3 5 6 7.

--After that,multilicationmultiplication of every element of array is performed in function multiplyEveryElement() method where FOR loop runs from 0 till the length-1 I.e. 4-1=3 as array is 0 indexed Array.

So,multiplication answer is 630.Args is returned from function to main() method in output variable.

--Output printedted.

Result of multiplying every element =630.

Posted by Mânïshå Mùlchåndânï    2015-03-12 05:48:25


Posted by Muhammad Shoaib Murtaza    2015-03-12 06:53:07


Posted by Induja Chinna    2015-03-12 07:23:21


Posted by Induja Chinna    2015-03-12 07:23:36

This dose is now closed and the winners are Goutham Singarapu,  for 'First Correct Comment', Goutham Singarapu, Mânïshå Mùlchåndânï,  for 'Best Comment' and Mânïshå Mùlchåndânï for the 'Popular Comment'. The 'lucky liker' is Shashanka Mogaliraju. Please login into Merit Campus using facebook, to claim your recharge. Go to to raise the recharge.

Posted by Prem Sai    2015-03-13 01:19:03

© meritcampus 2019

All Rights Reserved.

Open In App