A program is to find and display the sum of two numbers only if they are positive integers. | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
- 2

A program is to find and display the sum of two numbers only if they are positive integers.

Write this in Java using the following parameters; i. Taking the class name as „exam‟ ii. The output should be in a complete sentence

9th Jun 2020, 11:23 PM
Ibitoye Blessing
2 Réponses
+ 1
AJ Anant Equal and greater than zero would be a better choice since "0" is also a positive number.
10th Jun 2020, 4:21 AM
ogoxu
ogoxu - avatar
0
It's very easy task. Just check if both numbers are greater than 0. int sum = 0; if(n1 > 0 && n2 > 0 ) { sum = n1 + n2; }
9th Jun 2020, 11:32 PM
A͢J
A͢J - avatar