in 2d which dimension is optional at the declaration of array in java
Answers
Answered by
0
Answer:
In 2D, the second dimension is optional at the declaration of the array in java.
The second dimension is optional.
If we don't specify the second dimension, the compiler will not throw an error.
In Java, a two-dimensional array is nothing but an array of one-dimensional arrays.
Example:
class Example
{
public static void main(String[] args)
{
String[][] A = {{"Hi ", "Hello ", "Hey "}, {"Nirali"}};
System.out.println(A[0][0] + A[1][0]);
System.out.println(A[0][1] + A[1][0]);
System.out.println(A[0][2] + A[1][0]);
}
}
Output:
Hi Nirali
Hello Nirali
Hey Nirali
Similar questions