2013-05-02 91 views
-1

我需要幫助搞清楚我做錯了什麼。這是我的編碼到目前爲止。 我想繪製一個圓上的座標。我得到一個不是一個聲明錯誤。我得到一個不是一個聲明錯誤

public class MathClass 
{ 

    public static void main (String [] args) 
    { 

    double y1; 
    double y2; 
    System.out.println("Points on a Circle of Radius 1.0"); 
    System.out.printf ("%6s" , "x1", "y1", "x1" , "y2"); 
    System.out.println ("----------------------------------"); 
    for (double x1 = 1.00; x1> -1.10; x1 + -0.10) 
    { 
     double x1sq= Math.pow(x1,2); 
     double r = 1; 
     double y1sq = r- x1sq; 
     y1= Math.sqrt(y1sq); 
     System.out.printf("%.2f", x1, " ", y1); 

    } 

} 
+1

請發佈完整的錯誤。 – thegrinner 2013-05-02 15:50:20

回答

1

您的for循環中有語法錯誤。你可以把它改寫這樣的:

for (double x1 = 1.00; x1> -1.10; x1 -= 0.10) 
0

X1 + -0.10是你的問題,你有沒有想X1 + = -0.10

3

你的問題是你發佈的代碼的第10行。問題是x1 + -0.10是一個表達式,而不是一個語句(因此,你得到的「不是一個語句」錯誤)。您需要改爲x1 += -0.10。或者說,是它更清晰,使用-=而不是添加負,所以整個循環條件如下:

for (double x1 = 1.00; x1 > -1.10; x1 -= 0.10) 
{ ... } 
0

你的任務是錯誤的

使用x1 -=0.10

for (double x1 = 1.00; x1> -1.10; x1 -=0.10) 
    { 
     double x1sq= Math.pow(x1,2); 
     double r = 1; 
     double y1sq = r- x1sq; 
     y1= Math.sqrt(y1sq); 
     System.out.printf("%.2f", x1, " ", y1); 

    } 
相關問題