Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Ernesta Fernandez   on Apr 14 In Java Category.

  
Question Answered By: Latoya Murray   on Apr 14

The test
if(total == count)
must be done outside the loop
for (num = 1; num < count; ++num)
24 gets printed because 24 = 1+2+3+4+6+8. In your code, you don't get to verify
12.

Also, for efficiency, you may want to consider replacing this loop with:
for (num = 1; num <= count/2; ++num)

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Logic error Or get search suggestion and latest updates.


Tagged: