我的代碼風格有什麼問題嗎? 這是家庭作業,我試圖提交,但它說我的風格是錯誤的:/編碼風格有問題
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!
一個挑剔:改變'saidSecret()'簡單地說就是'return line.indexOf(secret)> = 0;'。 – user949300 2014-09-19 07:09:35
謝謝:)沒想到那 – Panthy 2014-09-19 07:10:50
這個問題更適合https://codereview.stackexchange.com/。 – 2014-09-19 07:20:25