double[][] arr = new double[2][3];
double[][] arr = new double[][]{ { 1.1, 2.2, 3.3 }, { 4.4, 5.5, 6.6 } };
double[][] arr = { { 1.1, 2.2, 3.3 }, { 4.4, 5.5, 6.6 } };
arr
" is an array of 2 elements, where each element is a 1-D array of 3 doubles.arr[i][j]
.int[][] arr = new int[4][];
arr[0] = new int[] { 11 };
arr[1] = new int[] { 22, 33 };
arr[2] = new int[] { 44, 55, 66 };
arr[3] = new int[] { 77, 88, 99, 110 };
for(int i=0; i<arr.length; i++) {
for(int j=0; j<arr[i].length; j++) {
System.out.print(arr[i][j] + ", ");
}
}
Methods with a variable number of arguments. These arguments are represented by ...
and internally collected into an array.
public static int sum(int... arr) {
int total = 0;
for(int num: arr)
total = total + num;
return total;
}
public static void main(String[] args) {
int result1 = sum(10, 20);
System.out.println("Result: " + result1);
int result2 = sum(11, 22, 33);
System.out.println("Result: " + result2);
}
If method argument is Object... args
, it can take variable arguments of any type.
Pre-defined methods with variable arguments:
PrintStream printf(String format, Object... args);
String format(String format, Object... args);