public class BouncingBalls
{
public static void main(String[] args)
{
double[] balls = new double [10];
double[] x = new double[1];
double[] y = new double[1];
double[] xspeed = new double[1];
double[] yspeed= new double[1];
for(int i = 0; i < 10; i++)
{
x[i] = 0.5;
y[i] = 0.5;
double r = 0.05;
xspeed[i] = Math.random() / (5 * 24);
yspeed[i] = Math.random() / (5 * 24);
while(true)
{
StdDraw.clear();
StdDraw.circle(x[i],y[i],r);
x[i] = x[i] + xspeed[i];
y[i] = y[i] + yspeed[i];
if (x[i] > 1 || x[i] < 0)
xspeed[i] = xspeed[i] * -1;
if (y[i] > 1 || y[i] < 0)
yspeed[i] = yspeed[i] * -1;
StdDraw.show(1000/ 24);
}
}
}
}
我需要在屏幕上打印 10 个弹跳球,我不知道我做错了什么,它不会打印所有 10 个。我不知道如何使用任何导入方法或类似的东西。所以如果有人可以帮助我,那就太好了!!!