package com.edu.gll.study;
public class shu {
public static void main(String[] args) {
String novel1[][] = new String[2][];//表示两本书
novel1[0] = new String[3];//第一本书
novel1[1] = new String[2];//第二本书
novel1[0][0] = "刘备";
novel1[0][1] = "关羽";
novel1[0][2] = "张飞";
novel1[1][0] = "鲁智深";
novel1[1][1] = "扶危济困";
//foreach语句遍历二维数组novel1
for(String[] book:novel1){
for(String word:book){//输出一本小说的词
System.out.println(word+"");
}
System.out.println();//换行
}
//传统for语句遍历二维数组novel
for(int i = 0; i < novel1.length; i++){
for(int j = 0; j < novel1[i].length; j++){
System.out.println(novel1[i][j]);
}
}
}
}
不规则二维数组的使用
最新推荐文章于 2024-10-03 07:17:26 发布