What will be the result of running the following code?

public class Test {
    public static void main(String[] args){
        float x = 0, y = 0;
        x = (float) (0.3 + 0.4);
        y = 0.3f + 0.4f;
        System.out.println(x==y);
    }
}
Explanation
Because of precision errors in floating point arithmetics, y = 0.70000005 and result is false.

Follow CodeGalaxy

Mobile Beta

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