【Java】转义字符

1、\t 制表符

\t?制表符,8个字节(8个英文状态下的空格)

public class Test {
        public static void main(String [] args) {
            /*Java中的字符使用的是Unicode编码*/
                System.out.println("helloworld");
                System.out.println("hello\tworld"); //hello占5个字符,8个空格没有占满,所以\t出来3个字符的位置
                System.out.println("helloooo\tworld");//helloooo占满了8个,会重新开一个制表位
                System.out.println("helloworld");
                System.out.println("张\t三"); //一个汉字占2个空格 \t出来6个空格的位置                   
        }
}

输出结果?

helloworld
hello      world
helloooo           world
helloworld
张       三

2、\n 换行

println():只能在输出之后换一行
\n :位置可在前,中,后,可以写多个

public class Test {
        public static void main(String [] args) {
           // System.out.println("helloworld"); 输出之后自动换一行
                System.out.print("\n\nhelloworld\n\n\nhelloworld"); //每个\n换一行
        }
}

3、\" 输出时显示一个"

4、 \\ 输出时显示一个\

public class Test {
        public static void main(String [] args) {
           // System.out.println("helloworld"); 输出之后自动换一行
                System.out.print("\n\nhelloworld\n\n\nhelloworld"); //每个\n换一行
                System.out.println("老师说:\"好好学习\"");
                System.out.println("http:\\\\www.baidu.com");
        }
}
评论 26
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杨幂等

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值