0
以下是我試圖如何顯示在Java中數組的數組元素
import java.lang.String.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
String [][] array1 = new String[][] {
{"One"},
{"One", "Two", "Three"},
{"One"," Four"," Five"},
{"One"," Four", "Six"," Seven"},
{"Seven", "Eight"," One"},
{"One"},
{"One"," Nine"},
{"One", "Nine"," Seven"},
{"One"," Nine"}
};
for (int row1=0;row1<=array1.length;row1++){
for (int cols=1 ;cols<array1[row1].length ;cols++){
System.out.println(array1[0][0] +" "+ array1[row1][cols]);
}
}
}
}
我想作爲
One
One Two
One Three
One Four
One Five
One Four
One Six
One Seven
Seven Eight
Seven One
One
One Nine and so on till the end of the array.
顯示元素的代碼的輸出是:
One Two
One Three
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 9
One Four
One Five
One Four
at javaapplication12.Main.main(Main.java:45)
One Six
One Seven
One Eight
One One
One Nine
One Nine
One Seven
One Nine
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
請建議我該怎麼做才能獲得優先輸出..任何幫助將不勝感激...
非常感謝... :) – user1949186 2013-02-09 09:28:42
@ user1949186最受歡迎... PLZ投票++ ......... :) – Chintan 2013-02-09 09:29:42