BlueJ 中的换行符不起作用( )

问题描述 投票:0回答:1

我试图在 blueJ 中添加一个换行符,但它不会工作,因为 String 的返回类型将返回文字字符。我都试过了 和 同样的结果。

    public String testNl(){
       String str1 = "1st Line";
       String str2 = "text 2nd";
       
       String linebreak = str1 + "\n" + str2;
       
       return linebreak;
    }

结果:

1st Line\ntext 2nd

java bluej
1个回答
0
投票

将return语句换成println语句就不会报错了

   String str1 = "1st Line";
   String str2 = "text 2nd";
   
   String linebreak = str1 + "\n" + str2;
   
   System.out.println(linebreak);
© www.soinside.com 2019 - 2024. All rights reserved.