如何在Java中打印“\ t”(如图所示)?

我想用Java打印反斜杠。 但每当我尝试时,它实际上将其视为\ t操作符。 双反斜杠不起作用。 我怎样才能做到这一点。

例如,通过添加另一个来逃避反斜杠

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

如果这不起作用,您的代码可能还有其他问题 – 如果这对您没有帮助,请发布。

你需要用另一个’\’来逃避’\’

 System.out.println("\\t"); 

双反斜杠有效。

 public static void main(final String[] args) { System.out.println("\\t"); } 

将输出\ t

 public static void main(String[] args) { System.out.println("\"\t\""); } 
 System.out.println("\"\\t\""); 

如果你甚至需要双引号:)

要在java中添加选项卡,其过程与c和java相同

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

在Java中: –
System.out.println("This will display the tab example \t After tab");

同样适用于New line
System.out.println("This will display the New Line example \n Next Line");

 System.out.println("\" + "t"); 

这个威尔打印: \t很容易!