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 @ 2022-10-31 18:44  乐美  阅读(129)  评论(0)    收藏  举报