Forums Register Login

sum up numbers

+Pie Number of slices to send: Send
Hi, in this program, supposed to add odd numbers
it works when num1 <= numb2 : "10, 1"
but when you enter num1 >=numb2 : "10,1" does not work and theres no errors
what condition i have to add (when numb1>=numb2) and where i have to locate it.
Thanks



+Pie Number of slices to send: Send
That's because you assume, in your code that num1 is less then or equal to num2.
Take a look at line 15
max() and min() in the Math class might be handy here.
+Pie Number of slices to send: Send
You need to check out your loop. It is custom to have the increment part also in the for loop.
+Pie Number of slices to send: Send
 

Juan Villena wrote:Hi, in this program, supposed to add odd numbers
it works when num1 <= numb2 : "10, 1"
but when you enter num1 >=numb2 : "10,1" does not work and theres no errors
what condition i have to add (when numb1>=numb2) and where i have to locate it.


Well personally, I'd do it right after they enter the numbers; the question is: what do you do if they enter them in the wrong order?

However, another way to do it without worrying about errors would be to just swap the two values if they're in the wrong order.

Winston
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1519 times.
Similar Threads
Problem with Sort Method
toString() method
Swap function in java
[HOMEWORK] Please need help with java project
Erroneous sym type What does this mean?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:23:31.