2013-05-02 46 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); 

    } 
相关问题