What will be the output of the following Java code?class multidimention_array {public static void main(String args[]){int arr[][] = new int[3][];arr[0] = new int[1];arr[1] = new int[2];arr[2] = new int[3]; int sum = 0;for (int i = 0; i < 3; ++i) for (int j = 0; j < i + 1; ++j)arr[i][j] = j + 1;for (int i = 0; i < 3; ++i) for (int j = 0; j < i + 1; ++j)sum + = arr[i][j];System.out.print(sum); } }

🎲 Try a Random Question  |  Total Questions in Quiz: 63  |  🧠 Study this quiz with Flashcards
This question is part of a full practice quiz:
Java Basics Practice Test: Data Types, Variables and Arrays — practice the complete quiz, review flashcards, or try a random question.

Quiz on integer, character, floating and boolean data types, variables, type casting and conversions and properties of arrays. Java has two types of data types: primitive data types and reference data types. Primitive data types are the basic data types that are built into the Java language. There are eight primitive data types in Java: byte: A byte is an 8-bit signed integer. short: A short is a 16-bit signed integer. int: An int is a 32-bit signed integer. long: A long is a 64-bit signed integer. float: A float is a 32-bit floating-point number. double: A double is a 64-bit... Show more

What will be the output of the following Java code?<br>class multidimention_array <br>{<br>public static void main(String args[])<br>{<br>int arr[][] = new int[3][];<br>arr[0] = new int[1];<br>arr[1] = new int[2];<br>arr[2] = new int[3]; <br>int sum = 0;<br>for (int i = 0; i < 3; ++i) <br>for (int j = 0; j < i + 1; ++j)<br>arr[i][j] = j + 1;<br>for (int i = 0; i < 3; ++i) <br>for (int j = 0; j < i + 1; ++j)<br>sum + = arr[i][j];<br>System.out.print(sum); <br>} <br>}