SC-202004030939_20200829-潘旭

日志

问题:

​ 问题内容:将字符串转换成字符

       String str = "abcdder,ldf." ;
        
        int s = str.length();
        System.out.println(s);
        char [] ch = new char[s] ;  
        for(int x = 0; x < s ; x++) {
            ch[x] = str.charAt(s);          
        }
        System.out.println(Arrays.toString(ch));
//运行出现:
//Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 12
//字符串索引越界异常
//程序运行能输出字符串的长度,然后会报出索引越界。


​ 问题来源:做题时遇到的的

​ 解决问题:

//然后改成这样:
        String str = "abcdder,ldf." ;
        
        int s = str.length();
        System.out.println(s);
        char [] ch = new char[s] ;  
        for(int x = 0; x < s ; x++) {
            ch[x] = str.charAt(x); //问题在这里,字符串的索引应该和数组下标同步。         
        }
        System.out.println(Arrays.toString(ch));
         
            

吐槽:

​ 考的很差,对自己的答卷很是不满意,每回选择题都错很多,不是不会做的原因,是自己太粗心(从小到大的毛病)。

​ 选择题只做了一遍,也没有再看一遍,只想着做后面的题 ,结果后面的题也做得很差 ,唉。。。。。很不甘心!!!!

标签


© 2021 成都云创动力科技有限公司 蜀ICP备20006351号-1