美文网首页
java字符串

java字符串

作者: 李昱俊 | 来源:发表于2017-12-27 20:24 被阅读0次
    String s= "helloworld";
            System.out.println(s.length());
            System.out.println(s.charAt(4));
            char n = s.charAt(4);
            System.out.println(n);
            System.out.println(s.indexOf("o",5));
            System.out.println(s.substring(0));
            System.out.println(s.substring(0,s.length()));
            char[] ch = s.toCharArray();
            for (int i = 0 ; i <ch.length;i++)
            {
                System.out.println(ch[i]);
            }
            String ss=String.valueOf(ch);
            System.out.println(ss);
    
    int[] arr = {1,2,3};
    String s="";
    s+="[";
    for (int i =0; i <arr.length;i++){
        if (i<arr.length-1){
            s+=arr[i];
            s+=",";
        }
        else {
            s+=arr[i];
            s+="]";
    
        }
    
    
    }
    
    
            System.out.println(s);
    
            String maxString = "woaijavawozhenaijavawozhendeaijavawozhendehenaijavaxinbuxinwoaijavagun";
    
            String minString = "java";
            int count = 0;
            int index;
            while ((index=maxString.indexOf(minString))!=-1)
            {
                count++;
                maxString = maxString.substring(index + minString.length());
            }
            System.out.println(count);
    
    • 将一个数字字符串转换成逗号分隔的数字串,即从右边开始每三个数字用逗号分隔


    
    Scanner scanner = new Scanner(System.in);
    
    String shu = scanner.next();
    
    String y =shu.substring(shu.length()-3,shu.length());
    String r =shu.substring(shu.length()-6,shu.length()-3);
    String h =shu.substring(0,shu.length()-6);
            System.out.println(h+","+r+","+y);
    

    相关文章

      网友评论

          本文标题:java字符串

          本文链接:https://www.haomeiwen.com/subject/nqsugxtx.html