How can I print “\t” (as it looks) in Java?

2020-07-10 06:54发布

I want to print backslash t in Java. But whenever I try, it actualy takes it as \t operator. Double backslash didn't work. How can I do that.

标签: java string
8条回答
Ridiculous、
2楼-- · 2020-07-10 07:14

Escape the backslash by adding another, for example

System.out.println("This is a tab \t and this is not \\t");

If this doesn't work, there might be something else wrong in your code - please post it if this doesn't help you.

查看更多
Rolldiameter
3楼-- · 2020-07-10 07:17
System.out.println("\"\\t\"");

if you need even the double quotes :)

查看更多
Luminary・发光体
4楼-- · 2020-07-10 07:19
public static void main(String[] args) { 
    System.out.println("\"\t\""); 
}
查看更多
成全新的幸福
5楼-- · 2020-07-10 07:22
System.out.println("\\"+"\\t");

Shows: \t

查看更多
forever°为你锁心
6楼-- · 2020-07-10 07:28

You need to escape the '\' with another '\'

System.out.println("\\t");
查看更多
手持菜刀,她持情操
7楼-- · 2020-07-10 07:28

To add tab in java the process same like c and java

In C:-
printf("This will display the tab example \t After tab");

In Java:-
System.out.println("This will display the tab example \t After tab");

Same will be for New line also
System.out.println("This will display the New Line example \n Next Line");

查看更多
登录 后发表回答