Menu
Topics Index
...
`

Array Output790


If you need explanation Read this topic

If you need Answer Take test on this topic

Array Output790
What will be the output of the following program?
class ArrayOutput
{
    public static void main(String s[])
    {
        int[][] input = {{3, 5, 6, 7}, {2, 4}, {1}, {2, 3, 4, 5}};
        int  result = 1;

        for(int i = 0; i < input.length; i++)
        {
            for(int j = input[2].length; j >= 0; j--)
            {
                result *= input[i][j];
            }
        }
        System.out.println("Result = " + result);
    }
}

A. Result = 12
B. Result = 604800
C. Compilation Error
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 C.. array cant find element in input Array.. so compilation error,..

Posted by Om Prakash Om    2014-09-12 04:19:01


ans a.
innr for loop executs ly 1 tim .each tim 1st value of single arr get multiplied.
so 3*2*1*2

Posted by NagaRaj Nataraj    2014-09-12 04:49:09


ans is d because in for loop while i=2 we dont have a[2][1] so array index out of bounds exception will be thrown

Posted by Pranavi Prakash    2014-09-12 04:49:54


d ,, becox a[2][1] is not found

Posted by Raju VarshnEy    2014-09-12 09:17:26


d

Posted by Ankur Verma    2014-09-12 10:29:59


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

Posted by Merit Campus    2014-09-15 04:50:00


© meritcampus 2019

All Rights Reserved.

Open In App