public class Main {
public static strictfp void main(String...args) {
int i = 0;
for(double x = 0 ; x != 13.08 ; x += 0.12) {
System.out.println(i++);
System.out.println(x);
}
}
}
The loop will run infinitely. The value of variable x will never become exactly 13.08 because of accuracy problems in floating-point operations. (Value 0.12 can't be precisely represented as a double, it will be represented approximately as 0.11999999... and so on). Correct condition would be: x <=13.08.
Login in to like
Login in to comment