Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

The product of all integers in an array

 
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.
 
Rancher
Posts: 1041
6
  • 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: 1041
6
  • 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.
 
How do they get the deer to cross at the signs? Or to read this tiny ad?
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic