Menu
Topics Index
...
`

Array Output782


If you need explanation Read this topic

If you need Answer Take test on this topic

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

    public static int multiplyEveryElement(int[] input, int result)
    {
        for(int i = 0; i < input.length; i++)
        {
            result *= input[i];
        }
    }
}

A. Result of multiplying every element = .
B. Result of multiplying every element = 630.
C. Result of multiplying every element = 630.0.
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.

here option  D:
because of in multiplyEveryElemnt()  method return type is int but
in method defination were not return any values thats why its give compile time error
result is compile time error(option D)

if we written (return result; in  multiplyEveryElemnt() method  it will compile successfully give result 630.0)

Posted by Goutham Singarapu    2015-02-11 09:00:55


ANS IS D (COMPILATION ERROR)

--Here,program for multiplication of elements of array is written.

--Array of integers named input is declared with 4 elements and result variable is declared to 1.

--After that multiplyEveryElement() is called by passing input array n result.

--In function,for loop runs from 0 till length of input array and inside that loop result stores the multiplication value of each element of array.

--But in the function signature int is used as return type but there is no return statement at the end of function no return statement is there. So,Compilation ERROR is there.

Posted by Mânïshå Mùlchåndânï    2015-02-11 12:51:35


Ans is D..here the concept is method returning values.we have the multiplyEveryElement() with this method we are receiving the int  array and the int value..in that array we have the 3,5,6,7 as elements..in the method we are multiplying the every element with result so after completion of the loop we have the result in the variable but we are not returning the value from the method but we write return type as int so we must return the value if not than the compiler will raise an error..

Posted by Uday Kumar    2015-02-11 14:52:00


d

Posted by Shubham Bansal    2015-02-11 16:25:57


This dose is now closed and the winners are Goutham Singarapu,  for 'First Correct Comment', Mânïshå Mùlchåndânï, Uday Kumar,  for 'Best Comment' and Uday Kumar for the 'Popular Comment'. The 'lucky liker' is Maheshwari Natarajan. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2015-02-12 04:48:51


© meritcampus 2019

All Rights Reserved.

Open In App