/*
 String(字符串)类型变量的使用
     *1.String属于引用数据类型;
     *2.String用双引号""进行定义;
 */
class StringTest{
    public static void main(String[] agrs) {
        String s1="Hello World!";
        System.out.println(s1);
        int number=1001;
        String numberStr="学号: ";
        String info=numberStr+number;//连接运算+,运算结果仍然为String类型。
        System.out.println(info);
        
        
        //*****************************************************************
        //练习1
        char c='a';//97;'A'->65
        int num=10;
        String str="hello";
        System.out.println(c+num+str);//107hello,先加法后连接
        System.out.println(c+str+num);//ahello10,两次连接运算
        System.out.println(c+(num+str));//a10hello,两次连接运算
        System.out.println((c+num)+str);//107hello,先加法后连接
        System.out.println(str+num+c);//hello10a,两次连接运算
        //完全准确!
        
        //******************************************************************
        //练习2
        //从控制台输出*    *(中间是一个tab键不是空格)
        System.out.println("*    *");
        String str0="*";
        char c0='\t';
        System.out.println(str0+c0+str0);//天才,我真的牛皮!!!
        System.out.println('*'+'\t'+'*');//加法运算,得到int型整数
        System.out.println('*'+"\t"+'*');//连接运算,可以得到目标输出
        System.out.println('*'+'\t'+"*");//先加法运算得到一个整数,后连接运算将整数与字符串"*"连接输出
        System.out.println('*'+('\t'+"*"));//两次连接运算,可以得到目标输出
    }
}

 

原文地址:http://www.cnblogs.com/NGZS/p/16845355.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性