• Post Reply Bookmark Topic Watch Topic
  • New Topic

add five integers one by one using arrays  RSS feed

 
Amrit Kaur
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i need help with this question,show how you can add five integers one by one using arrays. here is what i have done,am not quite sure if that's what is to be done?as the question says one by one can i have help please?

 
Randall Twede
Ranch Hand
Posts: 4696
8
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i don't see anything wrong with it. you will have to look at system out to see if it worked though
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read about for loops in the Java™ Tutorials. There may be a simpler way to do what you are doing there.
There is a way to do that in Java8 without writing a loop at all. You can use a method of the Arrays class to get your hands on an IntStream which handles all the elements of your array, and it has a sum() method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!