What will be displayed as a result of the following program execution?

public class Main {
    public static void main(String[] args) {
        Formatter formatter = new Formatter(Locale.ROOT);
        formatter.format("%.2E\n", 100.0/3.0);      //1
        formatter.format("%.2f", 100.0/3.0);        //2
        System.out.println(formatter);
    }
}
Explanation
Formatter is a formatting class in Java. 3.33E+01 will be a result of the line 1 execution, since "2" approximates the expression to the 2nd decimal place and E converts it into the engineering representation.
33.33 will be a result of the line 2 execution since a 2nd decimal place approximation is performed here as well.
Without Locale being explicitly specified the result would be dependent on the decimal and integer part separator specified in the system preferences.

Следи за CodeGalaxy

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

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