2012-02-07 79 views
0

新手程序員在這裏。試圖學習靜態方法和遞歸。不知道爲什麼每當我嘗試調用「drawCircle()」時都會收到「.class expected」錯誤。我的代碼如下。幫助PLZ?謝謝!試圖在java中調用一個函數,抱怨「.class expected」。

public class Drawliin 
{ 
    public static void drawCircle(int numberOfTimes, double radius, double center[]) 
    { 
     int rep = 1; 
     if (rep == 1) 
     { 
      StdDraw.circle(center[0], center[1], radius); 
      rep++; 
     } 
     else if (rep <= numberOfTimes) 
      { 
      StdDraw.circle(center[0 + radius], center[1], radius); 
      StdDraw.circle(center[0 - radius], center[1], radius); 
      StdDraw.circle(center[0], center[1 + radius], radius); 
      StdDraw.circle(center[0], center[1 - radius], radius); 
      rep++; 
      drawCircle(numberOfTimes, radius, center[]); 
      } 
     } 

    public static void main(String[] args) 
    { 
     int N = Integer.parseInt(args[0]); 
     double r = Double.parseDouble(args[1]); 
     StdDraw.setXscale(-10, 10); 
     StdDraw.setYscale(-10, 10); 
     double c[] = new double[2]; 
     drawCircle(N, r, c[]); 
    } 
} 

回答

5

它應該是:

drawCircle(N, r, c); 

你只是傳遞c。你不需要再次指出它是一個數組。

+0

我不認爲這是導致他的班級預期錯誤。 – Dodd10x 2012-02-07 16:47:31

+0

@拍客 - 你會錯誤的想法;) – 2012-02-07 16:51:10

0

在 '中心' 中刪除括號和 'c:

drawCircle(numberOfTimes, radius, center); 

drawCircle(N, r, c); 
1

你的問題是,這些行:

drawCircle(N, r, c[]); 
drawCircle(numberOfTimes, radius, center[]); 

他們應該是:

drawCircle(N, r, c); 
drawCircle(numberOfTimes, radius, center); 

你不'你需要再次將它定義爲一個數組,你在參數中做了這個。只需將參數傳遞給函數。