info@meritcampus.com    +91-85006-22255
...
`

Array Output812
What will be the output of the following program?
`class ArrayOutput{    public static void main(String s[])    {        int input[][] = {{2, 4, 0},                     {5, 5, 3},                     {1, 0, 0}};        System.out.println("Determinant of given matrix is : " + getDeterminant(input));    }    public static int getDeterminant(int matrix[][])     {        int result = 0;                result = (matrix[0][0] * (matrix[1][1] * matrix[2][2] - matrix[2][1] * matrix[1][2])                        - matrix[1][0] * (matrix[0][1] * matrix[2][2] - matrix[2][1] * matrix[0][2])                 + matrix[2][0] * (matrix[0][1] * matrix[1][2] - matrix[1][1] * matrix[0][2]));                return result;    }}`

 A. Determinant of given matrix is : 12 B. Determinant of given matrix is : 7 C. Determinant of given matrix is : 0 D. Compilation Error E. Runtime Error
Topic:

### User comments below.All of them might not be correct.

Answer is A....getDeterminant method does the below computation 2((5*0)-(3*0)) - 4((0*5)-(1*3)) + 0((0*5) - (1*3)) which is 12 that is returened to main and printed

Posted by Shashanka Mogaliraju    2014-11-20 12:40:53

ans a.in this program 2d array concept is used .Array of array,2d array comprised of many one dimensional array.here matrix is implemented as an array of arrays of int. the first dimension represents the rows, the second dimension represents the columns. in array the number of columns in a row need not be same. but in matrix number of rows and columns need to be same. in arrays you can initialize the row dimension without initializing the columns, since the number of columns need not be constant for all the rows. coming to this program 2d array is initialized with 3 one dimentional array,each one dimensional arrays have 3 elements. so both row and column length equal. in sop we called getDeterminant () method with input argument. in definition of getDeterminant ,local variable result initialized with 0. thn result is assigned with determinant value of 2d input array.result= (2*((5*0)-(0*3))) - (5*((4*0)-(0*0))) + (1*((4*3)-(5*0))) = ((2*0) - (5*0) + (1*12)) = 12 .func returns 12 sop printd

Posted by Maheshwari Natarajan    2014-11-20 19:50:12

This dose is now closed and the winners are Sai Ram,  for 'First Correct Comment', Maheshwari Natarajan,  for 'Best Comment' and Sai Ram for the 'Popular Comment'. The 'lucky liker' is Bolo Raven. 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    2014-11-21 02:22:51