• Post Reply Bookmark Topic Watch Topic
  • New Topic

multiple calls to static method via for loop  RSS feed

 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when the following code is executing, it only prints the factorial of one but I want to make multiple calls to the same method via the for loop as in the program.

 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your while loop goes into an infinite loop, it relies on counter, but counter never changes.
 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
very thanks to the quick reply and sorry for the silly question
I also found that the integer can only store till the factorial of 17 and should be modified to long type.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not integer, but int. You will suffer overflow errors long before 17!. I think you can only calculate 12! with an int.
 
manish awara
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why you use printf function to print the factorials.?
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
manish awara wrote:why you use printf function to print the factorials.?
Because that is a good way to print numbers on screen.
 
manish awara
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i didn't know that. thanks @Campbell Ritchie
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!