What will be displayed on the console?

public class Main {
    public static void main(String[] args) {
        int a = 10;
        int b = 100;
        double c = (double) (a/b);
        String str = String.format("%1.4f", c);
        System.out.println(str);
    }
}
Explanation
In this case, the result of dividing 2 integers will also be casted to an integer (0) and only after it casted to double (0.0).
%1.4f prints a floating point number with precisions of 4 digits after dot.
To bring 0.1000 on the console it is necessary to change the line double c = (double) (a / b) to the double c = (double) a/b .

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes