I'm trying to make a program to simulate the solar system.
for(int i=0;i<1000;i++) {
double X=(160*Math.cos((2*PI*i)/365));
double Y=(160*Math.sin((2*PI*i)/365));
posX=Math.round(X);
posY=Math.round(Y);
cadre.repaint();
sleep(200);
}
f.setVisible(false);
To make my planets turning around the sun, I have a formula; the problem is that i have a double number with this formula, and i can't make him become an int (i tried floor(X), Math.round(X), doesn't work (error : incompatible types : possible lossy conversion from long to int)
[
]
You'll see that it is not really java but he works as Java (it's some Javascool), so your advices will probably work for me!
解决方案
Add cast to int like:
posX = (int) Math.round(X);