我的编码风格有问题吗? 这是为家庭作业,我试图提交它,但它说我的风格是错误的:/
import java.util.Scanner;
public class Groucho {
String secret;
public Groucho(String secret) {
this.secret = secret;
}
public boolean saysSecret(String line) {
if (line.indexOf(secret) != -1)
return true;
else
return false;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter your secret word here: ");
String a = in.nextLine();
Groucho x = new Groucho(a);
System.out.println("Please enter a sentence until you win the game");
while (in.hasNextLine()) {
String inp = in.nextLine();
if (x.saysSecret(inp)) {
System.out.println("You have won $100 for saying " + a);
break;
}
else
System.out.println("Try again");
}
}
}
这是我的风格检查员所说的错误:
Request 1
File received, running checkstyle...
Starting audit...
Groucho.java:20: while child at indentation level 11 not at correct indentation, 12
Groucho.java:21: if at indentation level 11 not at correct indentation, 12
Groucho.java:22: if child at indentation level 15 not at correct indentation, 16
Groucho.java:22: method call child at indentation level 15 not at correct indentation, 16
Groucho.java:23: if child at indentation level 15 not at correct indentation, 16
Groucho.java:24: if rcurly at indentation level 11 not at correct indentation, 12
Groucho.java:25: else at indentation level 11 not at correct indentation, 12
Groucho.java:26: method call child at indentation level 15 not at correct indentation, 16
Audit done.
Done!
答案 0 :(得分:1)
我喜欢做的一件事是将换行符分组到块或段落中。我认为它使代码更容易阅读。至于你的错误信息,看起来你需要将你的行缩进一个空格?看起来它们比预期的要低一级。
答案 1 :(得分:0)
所以显然我只需要在每个方法之间添加一个空格。愚蠢,但是。