程序输出以下二维数组:

来源:百度知道 编辑:UC知道 时间:2024/06/15 08:52:44
程序输出以下二维数组:
1 2 9 10 25
4 3 8 11 24
5 6 7 12 23
16 15 14 13 22
17 18 19 20 21
谁能帮忙做一下?

这个是我以前的练习,应该和你的要求异曲同工。
自己稍微改改吧
/*
编写一个方法,返回一个double类型的数组;
数组中的元素通过解析字符串中的元素获得;
如:
"1,2;3,4,5;6,7,8"
对应的数组为:
d[0,0]=1.0 d[0,1]=2.0

d[1,0]=3.0 d[1,1]=4.0 d[1,2]=5.0

d[2,0]=6.0 d[2,1]=7.0 d[2,2]=8.0
*/
import java.util.*;

public class SplitString {
public static void main(String[] args) {
System.out.println("Please Input Your String!");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
System.out.println();
String[] sFirst = str.split(";");

double[][] d;

d = new double[sFirst.length][];

for(int i=0;i<sFirst.length;i++) {
String[] sSecond = sFirst[i].split(",");
d[i] = new double[sSecond.length];

for(int j=0;j<sSecond.length;j++) {
d[i][j] = Double.parseDouble(sSecond[j]);
}
}

for(int i=