【发布时间】:2015-02-10 22:46:27
【问题描述】:
这是我目前所拥有的。它告诉我,我在下面标记的行上有一个语法错误,说它分别需要一个“{”和一个“}”,而它们周围没有双引号。有什么建议吗?
public class attempt1 {
//use Euler-Richardson algorithm
//defining the initial conditions
double v0=30;
double theta=40;
double x0=0;
double y0=0;
double v0x=v0*Math.cos(Math.toRadians(theta));
double v0y=v0*Math.sin(Math.toRadians(theta));
double dt= .01;
double ax=0;
double ay=-9.8;
double x=0;
double y=0; //this line here, on the semi-colon
while (y>=0) {
double vx= v0x+1/2*ax*dt;
double vy= v0y+1/2*ay*dt;
double x= x0+1/2*vx*dt;
double y= y0+1/2*vy*dt;
if (y<=0){System.out.println(x);}
}
} //and right over here, on the brace itself
【问题讨论】:
-
您不能将语句放在任何方法(或构造函数或初始化程序)之外。
-
对不起,我在编码方面还很陌生(大概 2 周,哈哈)。你具体指的是哪里?
-
您需要将 while 循环放在一个方法中 - 可能看起来像
public static void main(String[] args) { /* while loop here */ } -
啊,是的,我刚试过这个。它似乎解决了我的问题。谢谢!