java在多行上分解字符串文字
有没有一种方法可以分解一行代码,使其在java中处于新行时仍能连续读取
public String toString() {
return String.format("BankAccount[owner: %s, balance: %2$.2f,\
interest rate: %3$.2f,", myCustomerName, myAccountBalance, myIntrestRate);
}
上面的代码当我在一行上完成这一切时,一切都很顺利,但是当我尝试在多行上完成这一切时,它就不起作用了
在python中,我知道您使用\开始键入新行,但在执行时打印为一行
这是一个Python示例,需要澄清。在python中,这将使用 反斜杠或()
print('Oh, youre sure to do that, said the Cat,\
if you only walk long enough.')
用户会将其视为:
Oh, youre sure to do that, said the Cat, if you only walk long enough.
在java中有类似的方法吗??谢谢大家!
# 1 楼答案
使用
+
运算符在新行上拆分字符串示例输出:
BankAccount[owner: TestUser, balance: 100.57, interest rate: 12.50]
# 2 楼答案
以下是Java的编码约定:
为了便于阅读,请始终在新行的开头添加连接运算符
https://www.oracle.com/technetwork/java/javase/documentation/codeconventions-136091.html#248
希望这有帮助
布雷迪