public class ArrayInt { public static void main(String [] args){ stringEqual(); arrayIntDot(); System.out.println("--------------------------------------------------------------------------"); arrayInt(); System.out.println("--------------------------------------------------------------------------"); arrayIntOne(); System.out.println("--------------------------------------------------------------------------"); } private static void stringEqual() { String str1=new String ("str"); String str2=new String ("str"); System.out.println(str1==str2); String str3="str"; String str4="str"; System.out.println(str3==str4); } private static void arrayIntDot() { String s="1,2,3,4;5,6,7,8;9,10,11,12,13"; //以split()方法 分解 String[] sFirst=s.split(";"); String[][] word=new String[sFirst.length][]; int flag=0; for(int i=0;i<sFirst.length;i++){ String[] sSecond=sFirst[i].split(","); System.out.println("sSecond length:"+sSecond.length); word[i]=new String[sSecond.length];//这步确定行不规则数组的每行长度 //为这个数组赋值 for(int j=0;j<sSecond.length;j++){ word[i][j]=sSecond[j]; } System.out.println("---------------这是第"+(i+1)+"次循环-------------------"); } //输出二维数组 System.out.println("输出二维数组-------------------"); for(int i=0;i<word.length;i++){ for(int j=0;j<word[i].length;j++){ System.out.print(word[i][j]+" "); } System.out.println(); } } private static void arrayInt() { int [][] arrayTemp={{1,2,3,4},{5,6,7,8},{9,10,11,12}}; for(int i=0;i< arrayTemp.length;i++){ for (int j=0;j<arrayTemp[i].length;j++){ System.out.println(arrayTemp[i][j]+" "); } } } public static void arrayIntOne(){ //0 1 2 3可以不换行? int arrayTemp[][]; arrayTemp=new int[3][]; arrayTemp[0]=new int[4]; arrayTemp[1]=new int[4]; arrayTemp[2]=new int[4]; for(int i=0;i< arrayTemp.length;i++){ for (int j=0;j<arrayTemp[i].length;j++){ arrayTemp[i][j]=j; System.out.println(arrayTemp[i][j]+" "); } System.out.println(); } } }