您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

将字符串数组分别存储在指定变量中

将字符串数组分别存储在指定变量中

public class j {

    static String sss = "male,O+,45,saudi,brain_diseases";
    static int size = sss.length();

    //I suggest you not to give them a start value or set them as null
    static String male = "";
    static String blood = "";
    static String age = "";
    static String nat = "";
    static String dis = "";

    static void func() {

        //it uses the "," character to breaks the string sss into pieces
        //so became into "male","O+","45","saudi","brain_diseases"
        String[] pieces = sss.split(",");

        //pieces[0] is the first piece so = "male"
        //pieces[1] is the second "O+" and so on
        male = pieces[0];
        blood = pieces[1];
        age = pieces[2];
        nat = pieces[3];
        dis = pieces[4];

        System.out.println(male);
        System.out.println(blood);
        System.out.println(age);
        System.out.println(nat);
        System.out.println(dis);

    }

    public static void main(String[] args) {

        func();        
    }
}
其他 2022/1/1 18:35:44 有545人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶