Java学习笔记day1——String类型变量

复制代码
/*
 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'+"*"));//两次连接运算,可以得到目标输出
    }
}
复制代码

 

posted @   乐美  阅读(122)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示