Redian新闻
>
请教大家:如何modify java code in order to compile
avatar
请教大家:如何modify java code in order to compile# Java - 爪哇娇娃
m*2
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)
但是加上之后,还是不对。
向请教大家,应该怎么解决这个问题?
非常感谢:)
avatar
z*e
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");
}
}
avatar
w*z
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{

avatar
c*e
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{

avatar
m*2
5
恩,是的。习惯了在网上做题,再回到真正eclipse, 就有了刚才的问题。谢谢大家答
疑解惑。
avatar
y*e
6
的确,这也是我想说的。

【在 w**z 的大作中提到】
: 改学python 吧。
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。