返回新行

时间:2015-11-02 22:28:27

标签: java string

public String toString()
{
    String name = "Customer name: " + this.name;
    String address = "Customer address: " +  street +  " " + city + " " + state + " " + zip;
    String bala = "Balance: " + bal;

    return name + "\n" + address + "\n" + bala;
}

我希望这些变量在三个单独的行中返回,但是实际的字符串" \ n"只是被添加到我想要新线的地方。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

未经测试,但可能有效:

return name + System.lineSeparator() + address + System.lineSeparator() + bala;