zoukankan      html  css  js  c++  java
  • 字符串分割+二维数组 Day15练习

    package com.sxt.arrays.test;
    
    import java.util.Arrays;
    /*  1,2,3,4!5,6,7!8,9!12,456,90!32
     *     将此字符串以叹号为分割存入二维数组中
     * 知识点:字符串+数组
     */
    public class TestArray {
        public static void main(String[] args) {
    
            String s = "1,2,3,4!5,6,7!8,9!12,456,90!32";
            String[] split = s.split("!");//分割  返回字符串数组
            System.out.println(Arrays.toString(split));
            System.out.println("split.length:"+split.length);//二维数组中一维数组的个数
            System.out.println("split[0]:"+split[0]);
            
            int [][]arr = new int[split.length][];//split.length:二维数组中一维数组的个数
            System.out.println("---------------------------");
            for(int i=0; i<split.length; i++){
                String[] split2 = split[i].split(",");//每个一维数组内的元素是一个整体  所以以逗号分割
                //System.out.println("---->"+Arrays.toString(split2));
                arr[i] = new int[split2.length];//初始化一维数组!否则:NullPointerException  动态赋值
                for(int j=0; j<arr[i].length; j++){
                    arr[i][j] = Integer.parseInt(split2[j]);
                    System.out.print(arr[i][j]+" ");
                }
                System.out.println();
            }
    //        [1,2,3,4, 5,6,7, 8,9, 12,456,90, 32]
    //        split.length:5
    //        split[0]:1,2,3,4
    //        ---------------------------
    //        1 2 3 4 
    //        5 6 7 
    //        8 9 
    //        12 456 90 
    //        32 
    
        }
    }
  • 相关阅读:
    自己搭建二维码接口
    HTML CSS SPRITE 工具
    Codeforces Round #636 (Div. 3) 题解
    Codeforces Round #612 (Div. 1+Div. 2)
    计树问题小结 version 2.0
    Educational Codeforces Round 85 (Rated for Div. 2) 题解
    luogu6078 [CEOI2004]糖果
    luogu [JSOI2012]分零食
    多项式全家桶
    生成函数小结
  • 原文地址:https://www.cnblogs.com/qingfengzhuimeng/p/6747090.html
Copyright © 2011-2022 走看看