Menu
Topics Index
...
`

Integer Array Addition


If you need explanation Read this topic

If you need Answer Take test on this topic

Integer Array Addition
At what line does the program fail to compile?
public class IntegerAddition {

    static int total = 0;

    public static void main(String[] args) {
        int a[] = { 2, 3, 4}; /* LINE A */
        int[] b = new int[4];
        int c[] = new int[] { 5, 6, 7}; /* LINE B */
        int total[][] = { a, b, c}; /* LINE C */

        for (int[] array1d : total) {
            for (int element : array1d) {
                IntegerAddition.total += element; /* LINE D */
            }
        }
        System.out.println("Total = " + IntegerAddition.total);
    }
}

A. LINE A
B. LINE B
C. LINE C
D. LINE D
E. No Compilation Errors
Topic: Unknown

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 must be E .. no compilation errors..as we cn define two dimensional arrays using single dimensional arrays

Posted by Pramod Jain    2013-10-22 12:37:32


e is answer we get 27 as output. a 2 dim array can be created with {} which means 3 rows and 1 col. all the array declarations are valid here. first a is cerate and assign 2nd array b is just assign size for array. line d has no problem

Posted by Karteek Paruchuri    2013-10-22 12:43:30


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

Posted by Merit Campus    2013-10-23 10:19:39


© meritcampus 2019

All Rights Reserved.

Open In App