samedi 8 juin 2019

How can I properly rewrite the following if statement to a conditional statement? Using a multiplication compound assignment operator

I'm attempting to rewrite the following if statement as a conditional statement.

if (hours > 40) wages *= 1.5; else wages *= 1;

Here is my attempt that works, but I don't think I used the multiplication compound assignment operator correctly or at all.

int hours = 50, wages = 20; System.out.println("Wages = " + (hours > 40 ? wages * 1.5: wages * 1));

Aucun commentaire:

Enregistrer un commentaire