一维数组
package java_study.week4;
public class Arr {
public static void main(String[] args) {
String class1[] = {
"张三","李四","王五","赵六"
};
System.out.println("此班级有"+class1.length+"人" );
}
}
二维数组
public class Arrays {
public static void main(String[] args) {
char arr[][]=new char[4][]; /
arr[0]=new char[]{'床','前','明','月','光'};
arr[1]=new char[]{'疑','是','地','上','双'};
arr[2]=new char[]{'举','头','望','明','月'};
arr[3]=new char[]{'低','头','思','故','香'};
System.out.println("---横版---");
for(int i=0;i<4;i++){
for(int j=0;j<arr[i].length;j++){
System.out.print(arr[i][j]);
}
if(i%2==0){
System.out.print(",");
}
else{
System.out.print("。");
}
System.out.println();
}
System.out.println("---竖版---");
for(int j=0;j<arr.length;j++){
for(int i=3;i>=0;i--){
System.out.print(arr[i][j]);
}
System.out.println();
}
System.out.println(",。,。");
}
}
网友评论