What values will variables x and i finally have:

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);
        }
    }
}
Explanation
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.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Java
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты