• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

sum up numbers

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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



 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to check out your loop. It is custom to have the increment part also in the for loop.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
rubbery bacon. crispy tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic