lundi 6 juillet 2015

Conditional if-else statement in java [duplicate]

This question already has an answer here:

I am unable to understand how this code prints 50.0

public class Pre
{
    public static void main(String[] args)
    {
        int x=10;
        System.out.println((x > 10) ? 50.0 : 50);
    }
} 

It should print 50,I guess...

And isn't the above code is equivalent to this(below) code,

public class Pre
{
    public static void main(String[] args)
    {
        int x=10;
        if(x>10)
            System.out.println(50.0);
        else
            System.out.println(50);
    }
}

If they are equivalent,then why 1st one prints 50.0 and 2nd one prints 50?

Aucun commentaire:

Enregistrer un commentaire