m******2 发帖数: 48 | 1 比如说,我们练习都会从
public boolean xyzThere(String str) {
return str.contains("xyz") && !str.contains(".xyz");
}
直接开始。
但是如果把以上代码放到eclipse 或者compile and execute java online上的main
class 里,
给出错误是:
at least one public class is required in main file
所以在开头又加上
public class HelloWord{
错误是缺少 public static void main(String []args)
但是加上之后,还是不对。
向请教大家,应该怎么解决这个问题?
非常感谢:) |
z****e 发帖数: 54598 | 2 ft
还是先找本java的教材看看吧
这种问题不会的话,是基本概念问题
前几章就会说
public class MyClass{
public boolean xyzThere(String str){...}
public static void main(String[] args){
MyClass myClass = new MyClass();
myClass.xyzThere("This is parameter");
}
} |
w**z 发帖数: 8232 | 3 改学python 吧。
【在 m******2 的大作中提到】 : 比如说,我们练习都会从 : public boolean xyzThere(String str) {
: return str.contains("xyz") && !str.contains(".xyz");
} : 直接开始。 : 但是如果把以上代码放到eclipse 或者compile and execute java online上的main : class 里, : 给出错误是: : at least one public class is required in main file : 所以在开头又加上 : public class HelloWord{
|
c*********e 发帖数: 16335 | 4 main class的壳子是机器自动给你生成的吧,不用你自己写main {}
【在 m******2 的大作中提到】 : 比如说,我们练习都会从 : public boolean xyzThere(String str) {
: return str.contains("xyz") && !str.contains(".xyz");
} : 直接开始。 : 但是如果把以上代码放到eclipse 或者compile and execute java online上的main : class 里, : 给出错误是: : at least one public class is required in main file : 所以在开头又加上 : public class HelloWord{
|
m******2 发帖数: 48 | 5 恩,是的。习惯了在网上做题,再回到真正eclipse, 就有了刚才的问题。谢谢大家答
疑解惑。 |
y****e 发帖数: 23939 | 6 的确,这也是我想说的。
【在 w**z 的大作中提到】 : 改学python 吧。
|