码迷,mamicode.com
首页 > 编程语言 > 详细

Java\学习——字符串

时间:2018-09-17 17:46:46      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:ati   ann   upper   param   imp   ted   todo   char   generated   

import java.util.Scanner;


public class cys1 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int a[];
        a=new int[5];
        for(int i=1;i<=4;i++)
        {
            a[i]=i;
            System.out.println(a[i]);
        }
        System.out.println("a的长度"+a.length);
//        Scanner in =new Scanner(System.in);
//        String cys;
//        cys=in.nextLine();
//        System.out.print(cys+","+"我是帅帅!!!");

//        int b[][]=new int[2][5];
//        for(int i=0;i<b.length;i++){
//            for(int j=0;j<5;j++){
//                b[i][j]=i*2+j;
//                System.out.print(b[i][j]);
//            }
//            System.out.println();
//        }
//        System.out.println("b[0]的长度"+b[0].length);
        String s="abcdefg love";
        //返回第6个字符,字符从0开始
        System.out.println(s.charAt(6));
        System.out.println(s.toUpperCase());
        //返回从3到10的字串
        System.out.println(s.substring(3,10));
        String c="aas";
        //返回s-c
        System.out.println(s.compareTo(c));
        
    
    }

}

技术分享图片

 技术分享图片

 

 

StringBuffer 为可以修改的字符串

        str.append("hhh");
        System.out.println(str);
        str.insert(1, "cys");
        System.out.print(str);

技术分享图片

 

Java\学习——字符串

标签:ati   ann   upper   param   imp   ted   todo   char   generated   

原文地址:https://www.cnblogs.com/caiyishuai/p/9662848.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!