简单的问题,可能是重复的,但在搜索时我无法找到我想要的东西。
那么,在Java中哪个语法更好?
var
或......
for
在这两种情况下,error: "line 1 did not have 42 elements"
已在其他地方初始化。因此,dat <- read.table(header = TRUE, row.names = 1, text = "name a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28 a29 a30 a31 a32 a33 a34 a35 a36 a37 a38 a39 a40
077 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 1 0 1 1 0 0 0
3FF 0 0 0 1 0 1 0 1 1 1 1 1 1 1 0 0 1 1 0 1 1 1 0 0 0 1 1 0 0 0 0 1 0 1 1 1 1 0 0 0
AAS 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Ale 0 1 0 1 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 1 0 1 0 0 0 1 0 0 0 1 0 0 1 1 0 1 1 0 0 0
Ali 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 0 1 1 0 0 1 1 1 0 1 1 1 0 0 0 0 0 0 1 0 1 1 0 1 0
Alt 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 0 1 1 0 0 1 1 1 0 0 0 1 0 0 0 0 1 0 1 0 1 0 0 0 0
Ama 0 0 0 1 0 0 0 1 1 0 0 1 1 1 0 0 1 0 0 1 1 1 1 0 1 1 1 1 0 0 0 0 0 0 0 1 1 0 0 0
Ano 0 0 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 1 0 1 0
Aro 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 0 1 0 0 1 0 1 0 0 0 1 1 1 0 0 0 0 0 1 0 1 1 0 0 0
Be1 0 0 0 1 0 0 0 1 0 0 0 0 1 0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 0 0 0 0 0 0 0 1 1 0 0 0
Uni 0 1 0 1 0 0 0 1 1 0 0 0 0 1 1 0 1 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 0 0
Wet 0 0 0 1 0 1 0 1 0 0 0 1 1 1 0 0 1 0 0 1 1 1 0 0 0 1 1 0 0 0 0 0 0 1 0 1 1 0 0 0
Whi 0 0 0 1 0 0 0 1 1 0 0 0 0 1 0 0 1 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 1 1 0 0 0
Yel 0 0 0 1 0 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1 0 1 0
Zee 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 0 1 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 1 1 0 0 0")
循环的第一部分是空的。但是,它节省了一行代码。
哪种做法更好,更受欢迎?
是否有更好的方式发布这些类型的问题?
答案 0 :(得分:4)
这完全取决于您关注的风格指南。
但是,如果你是一个提出样式指南的人,我会建议使用for循环语法。为什么?因为所有的循环结构都在一行中,所以更容易识别错误,更容易确定上下文。