启明星网站建设,雨花台网站建设,上海平台网站建设哪家有,廊坊建手机网站input: [[1,2,3 ], [4, 5,6], [7,8]]
output: [[1, 2, 3], [4, 5, 6], [7, 8]]
思路
按行读入, 然后进行字符串处理, 将其他字符替换为空字符.在split(,) repalceAll(“\s”,“”), 将所有空白字符替换成空字符(包括空格, 制表, 换行等)
代码实现
import java.util.*;publ…input: [[1,2,3 ], [4, 5,6], [7,8]]
output: [[1, 2, 3], [4, 5, 6], [7, 8]]
思路
按行读入, 然后进行字符串处理, 将其他字符替换为空字符.在split(,) repalceAll(“\s”,“”), 将所有空白字符替换成空字符(包括空格, 制表, 换行等)
代码实现
import java.util.*;public class test {public static void myFunc(ArrayListArrayListInteger arr){//测试展示System.out.println(arr);}public static void main(String[] args) {Scanner sc new Scanner(System.in);ArrayListArrayListInteger arr new ArrayList();while (sc.hasNextLine()) {ArrayListInteger row new ArrayList();String s sc.nextLine();/*[[1,2,3] ,[3,4,5]]*/String[] list s.trim().replace(],,).replace([, ).replace(], ).replace( ,).split(,);for (int i 0; i list.length; i) {int tmp Integer.parseInt(list[i]);row.add(tmp);}arr.add(row);}myFunc(arr);}
}