I am trying to go through a for loop and it is just like any other for loop but it seems to be infinite; I must be doing something stupid. Can anyone see it?
double x;
for(x = -1; x < 1; x+=2/20) {
double y = b * Math.sqrt(1-Math.pow(x-FocusToCenter, 2));
System.out.println("X:"+x+" Y: "+roundFourDecimal(y));
}
And if change x+=2/20, to x+=0.1 then it is perfectly fine.
What does
2/20evaluate to ? I suspect since they’re both integers, you’re getting a 0, and hence not increasingxat all.Trying expressing them as doubles e.g.
2.0 / 20.0