小编Pro*_*esh的帖子

在多行上分解字符串文字

是否有办法打破一行代码,以便尽管在java中的新行上它被读取为连续的?

public String toString() {

  return String.format("BankAccount[owner: %s, balance: %2$.2f,\
    interest rate: %3$.2f,", myCustomerName, myAccountBalance, myIntrestRate);
  }
Run Code Online (Sandbox Code Playgroud)

上面的代码,当我在一行上执行所有操作时,一切都很有效,但是当我尝试在多行上执行此操作时,它不起作用.

在python中,我知道你使用\来开始在新行上键入,但在执行时打印为一行.

Python中的一个例子来澄清.在python中,这将使用反斜杠或()在一行上打印:

print('Oh, youre sure to do that, said the Cat,\
 if you only walk long enough.')
Run Code Online (Sandbox Code Playgroud)

用户会将此视为:

Oh, youre sure to do that, said the Cat, if you only walk long enough.
Run Code Online (Sandbox Code Playgroud)

在java中有类似的方法吗?谢谢!

java string string.format

6
推荐指数
1
解决办法
8047
查看次数

标签 统计

java ×1

string ×1

string.format ×1