Java——解析二维数组

Description

读入一个字符串,该字符串表示一个整型二维数组d,数组中的元素通过解析字符串参数获得。例如,字符串参数:“1,2;3,4,5;6,7,8”,对应的数组为:
d[0,0] = 1 d[0,1] = 2  
d[1,0] = 3 d[1,1] = 4 d[1,2] = 5
d[2,0] = 6 d[2,1] = 7 d[2,2] = 8
打印这个数组各元素的内容

Input

字符串

Output

二维数组各元素

Sample Input

1,2;3,4,5;6,7,8

Sample Output

d[0,0] = 1 d[0,1] = 2
d[1,0] = 3 d[1,1] = 4 d[1,2] = 5
d[2,0] = 6 d[2,1] = 7 d[2,2] = 8
import java.util.*;

public class Main {

    public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    String str = scan.nextLine();

    System.out.print("d[0,0] = " + str.charAt(0));

    int col = 0;//列

    int row = 0;//行

    for(int i = 1;i

你可能感兴趣的:(Java)