• Post Reply Bookmark Topic Watch Topic
  • New Topic

The product of all integers in an array  RSS feed

 
James Allen A.
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose my question is broader than for just integers, but I really mean for all numbers in the ArrayList. Is there a method for returning the product for all numbers within the ArrayList? If my ArrayList values are [2, 5, 10] I would like it to return 100. I'm not sure it will solve the road block I've hit in my program but I want to give it a crack.
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about writing it?

A sidenote: think about the appropriate return data type. Multiplication can lead fast to integer overflow.
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
13 factorial does not fit into an int.

2 2 2
3 6 6
4 24 24
5 120 120
6 720 720
7 5040 5040
8 40320 40320
9 362880 362880
10 3628800 3628800
11 39916800 39916800
12 479001600 479001600
13 1932053504 6227020800
 
James Allen A.
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just felt like I had my hands full enough with the rest of the code. I suppose I could give it a shot. Maybe integers aren't the best choice. I'm writing a coin calculation program and hadn't considered that the user would enter a large number for a coin but I suppose I should account for that.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!