+ 1

How to answer this?

Can i ask how to code this question using selection? (Java:BlueJ) Question: A program requires a user to enter two non-negative integer values. If any of the values entered is negative, the message "Number must be non-negative" is displayed and the algorithm terminates. Otherwise, it displays the sum of the values if the first values is less than the second value. Or else, the product of the two values is displayed.

23rd Feb 2019, 12:43 PM
Leonard Lidwin
Leonard Lidwin - avatar
2 Respostas
+ 5
Declare first variable. Declare second variable. Input to first variable. Input to second variable. If first variable or second variable is negative Print "Number must be non-negative" Else if first variable smaller than second variable Print first variable + second variable Else Print first variable * second variable Just convert the above to Java, and show your attempts if you have any issues.
23rd Feb 2019, 1:34 PM
Hatsy Rei
Hatsy Rei - avatar
0
how to terminate the program when its negative? thx for your feeback btw :)
24th Feb 2019, 6:10 AM
Leonard Lidwin
Leonard Lidwin - avatar