Topics Index

Array Output779

If you need explanation Read this topic

If you need Answer Take test on this topic

Array Output779
What will be the output of the following program?
class ArrayOutput
    public static void main(String s[])
        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 result = 1;
        for(int i = 1; i < input.length; i++)
            result *= input[i];
        return result;

A. Result of multiplying every element = 210.
B. Result of multiplying every element = 90.
C. Result of multiplying every element = 630.
D. 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 Option A... Execution starts from main() method here we are creating array of integers with the name input and we are initializing input with the values input[0]=3,input[1]=5,input[2]=6,input[3]=7.. after that we are taking an integer variable output and we are initializing this variable by calling multiplyEveryElement(input) method passing input[] variable as an argument after that compiler will go to this method inside this we are creating a variable result  initialized with the value 1 after that we are using for-loop to get multiplication of the elements inside that array we are taking the range of for-loop from i=1 to i<input.length=4 and i++ that means multiplication will start from 2nd element of an array i.e from input[1]=5 and inside for-loop we have one stmt result*=input[i] means result=result*input[i] so after execution of for-loop we have result value as result=1*5*6*7=210.... after that compiler will return result value to the main method there we are printing result value so It will print                                 "Result of multiplying every element = 210. so Option A is Ans

Posted by Bhagi Bhagyasri    2015-01-29 04:38:08

ANS IS A (210)

--Here,Multiplication of array is done.

--Here,Array of integers named input is declared with the
values 3,5,6,7.


--Here,Function is written in which this array of integers
is passed in which "FOR LOOP" is written which runs from
1 till the length of array.

--But here multiplication is performed from 1.
i.e. input[1]=5*input[2]=6*input[3]=7=210.

--Therefore,Result of multiplying every element=210.

Posted by Mânïshå Mùlchåndânï    2015-01-29 18:32:50

This dose is now closed and the winners are Bhagi Bhagyasri,  for 'First Correct Comment', 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 Ammad Islam. Please login into Merit Campus using facebook, to claim your recharge. Go to to raise the recharge.

Posted by Merit Campus    2015-01-30 05:10:23

© meritcampus 2019

All Rights Reserved.

Open In App