Java 中数组类型
Java 支持一维和多维数组。请看以下示例
示例
public class Tester { public static void main(String[] args) { double[] myList = {1.9, 2.9, 3.4, 3.5}; // Print all the array elements for (double element: myList) { System.out.print(element + " "); } System.out.println(); int[][] multidimensionalArray = { {1,2},{2,3}, {3,4} }; for(int i = 0 ; i < 3 ; i++) { //row for(int j = 0 ; j < 2; j++) { System.out.print(multidimensionalArray[i][j] + " "); } System.out.println(); } } }
输出
1.9 2.9 3.4 3.5 1 2 2 3 3 4
广告