- public class Demo {
- public static void main(String[] args) {
- String[][] arr = new String[4][];
- arr[0] = new String[]{"name","age","subject","grade"};
- arr[1] = new String[]{"张三","18","数学","89"};
- arr[2] = new String[]{"李四","20","英语","60",""};
- arr[3] = new String[]{"张小三","18","数学","89"};
-
- printArray(arr);
- }
- public static void printArray(String[][] arr){
- for(int i=0;i<arr[0].length;i++){
- System.out.print(arr[0][i]+" ");
- }
- System.out.println();
- for(int i=1;i<arr.length;i++)
- {
- for(int j=0;j<4;j++)
- {
- System.out.print(arr[i][j]+" ");
- }
- System.out.println();
- }
- }
- }
复制代码 用二维数组也可以,但是不能动态操作,有些麻烦,可以考虑用集合解决。{:soso_e113:} |