gpt4 book ai didi

java - 错误 : class, 接口(interface),或枚举预期的 JCreator

转载 作者:行者123 更新时间:2023-12-01 11:44:25 25 4
gpt4 key购买 nike

我在我的项目中创建了一个名为 Student_Tester.java 的新类。我将使用这个测试器类来创建 Student 对象的实例。现在我尝试创建输出,但不断出现以下错误:

error: class, interface, or enum expected

谁能帮我解决这个问题吗?

这是代码:

public class student_tester {

public static void main (String [] args) {
Student student01 = new Student ("Tom Brown", "40030103", "1");
}
}
System.out.printf("%s (%s) is currently studying %s, %s and %s at Level %d", student01.getName(), student01.getNumber(), student01.getModule(1), student01.getModule(2), student01.getModule(3), student01.getLevel());

最佳答案

您的 printf 语句是在类主体之外定义的。试试这个:

public class student_tester {

public static void main (String [] args) {
Student student01 = new Student ("Tom Brown", "40030103", "1");
System.out.printf("%s (%s) is currently studying %s, %s and %s at Level %d", student01.getName(), student01.getNumber(), student01.getModule(1), student01.getModule(2), student01.getModule(3), student01.getLevel());
}
}

作为旁注,请考虑根据naming convention命名您的类。 :

Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).

关于java - 错误 : class, 接口(interface),或枚举预期的 JCreator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29266191/

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