看板 java 關於我們 聯絡資訊
※ 引述《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
chrisQQ:一個檔案只能有一個「public class」 06/03 20:01
感謝提出修正^^
peter11016:喔 感謝有時候就是少根筋 06/03 20:04
※ 編輯: alvin781205 來自: 118.168.67.88 (06/04 03:09)