mercredi 10 juin 2015

The ? expression in Java

I'm taking a introduction course in Java and I have a question about the ? expression (I've done some C# programming) but I'm not that familiar with it there either.

If I have this if statement, how do I use the ? on it? I have a task where I'm supposed to compare three variables in different ways and I hate to have alot of if statements.

    //Task b (If var3 is divisible with var2)
    if(var3 % var2 == 0)
    {
        System.out.println("\n" + var3 + " is divisible with " + var2);
        System.out.println(var3 + " divided with " + var2 + " is: " + var3 / var2);
    }
    else
    {
        System.out.println("\n" + var3 + " is not divisible with " + var2);
    }

This just look messy.. It's okay to turn it in like this but I personally think it look awful.

Aucun commentaire:

Enregistrer un commentaire