展開全部
你試一下這個行不行,輸入的時候是數字e69da5e6ba903231313335323631343130323136353331333335313138,數字,數字;數字,數字。。。。。的格式,你把我注釋的那個輸入行(String stInput = input.next();
)的注釋去掉,把我字符串寫死的那行(String stInput = "1,2,3;4,5;7,8,9";
)刪掉,就可以輸入了public?static?void?main(String[]?args)
{
Scanner?input?=?new?Scanner(System.in);
System.out.println("格式如下:1,2,3;4,5;7,8,9。輸入數字:");
//?String?stInput?=?input.next();
/**?暫時寫死了,方便測試,你將下面這句注釋,上面那句打開即可?*/
String?stInput?=?"1,2,3;4,5;7,8,9";
//?輸入按;(英文分號)分割成字符串數組
String[]?stArray?=?stInput.split(";");
//?按字符串長度聲明二維數組
double[][]?arResults?=?new?double[stArray.length][];
for?(int?i?=?0;?i?
{
//?字符串數組用分割成和目標結致字符串
String[]?stForChange?=?stArray[i].split(",");
//?第二維開辟空間
arResults[i]?=?new?double[stForChange.length];
for?(int?j?=?0;?j?
{
arResults[i][j]?=?Double.parseDouble(stForChange[j]);
}
}
/**循環輸出*/
for?(double[]?i?:?arResults)
{
for?(double?j?:?i)
{
System.out.print(j+"??");
}
System.out.println();
}
}