gpt4 book ai didi

java - 编码风格有问题

转载 作者:行者123 更新时间:2023-12-01 12:30:54 26 4
gpt4 key购买 nike

我的编码风格有问题吗?这是作业,我试图提交它,但它说我的风格是错误的:/

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!

最佳答案

我喜欢做的一件事是使用换行符将相关代码分组为 block 或段落。我认为这使代码更容易阅读。至于您的错误消息,看起来您需要将行缩进一格?看来它们比预期低了一级。

关于java - 编码风格有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25928122/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com