作者alvin781205 (判判)
看板java
标题Re: [问题]请问我哪里打错了
时间Wed Jun 3 17:26:24 2009
※ 引述《peter11016 (邵ㄎㄡ)》之铭言:
: public class test
: {
: public static void main(String[] args)
: {
: int i=star(5);
: System.out.println(i+"stars printed");
: }
: }
: public star(int n)
: {
: int j;
: for(j=1;j<=2*n;j++)
: System.out.println("*");
: System.out.println("\n");
: return 2*n;
: }
: 怎麽出现这样的错误class,interface,orenum expected
public class test
{
public static void main(String[] args)
{
test a= new test();
int i=a.star(5);
System.out.println(i+" stars printed");
}
public int star(int n)
{
int j;
for(j=1;j<=2*n;j++)
System.out.println("*");
System.out.println("\n");
return 2*n;
}
}
这样就没有错误error了
出来的结果是一行一个* 共10行
star那里你需要用一个物件,去call method (@@对这些名词我不太会分只会写,有误否?)
而且,star你回传的是int 在method开头也得写上int
另外,你的method要包在class里面才对
一个档案只能有一个public class
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.4.234
1F:推 chrisQQ:一个档案只能有一个「public class」 06/03 20:01
感谢提出修正^^
2F:推 peter11016:喔 感谢有时候就是少根筋 06/03 20:04
※ 编辑: alvin781205 来自: 118.168.67.88 (06/04 03:09)