File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiples project no output

 
Tim Hoang
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just made this to get the final answer for this question. "Find the sum of all the multiples of 3 or 5 below 10000." I haven't got no errors on my code, but I also did not get an answer out of my code. What could be the problem?


 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim, When these line of code execute

then value of f and t becomes 2000 and 3333 respectively. so it will not enter into if condition and else condition execute.
 
Tim Hoang
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just declaring that variable to equal to the max multiple (2000 and 3333), but how come it doesn't go through the if else statement? What should I change then without messing up the rest?
 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Hoang wrote:how come it doesn't go through the if else statement?


Print some statement in else block then you will know that it is executing the else block.

 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In if condition you had written that

it means when f and t both are zero then only it execute if condition but here value of f and t are 2000 and 3333 respectively. so it is executing else statement.
 
Tim Hoang
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh i knew what happened(i wanted it to be true), what i forgot was for it to loop back in making it true. I added while loop but it doesn't work?

 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try like this:

 
Tim Hoang
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dam your good, nice and simple, i will rework around my code. thanks for giving me an example on using % usefully.
 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Hoang wrote:thanks for giving me an example on using % usefully.


Glad to hear it helps you.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic