• 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

storing values within a loop  RSS feed

 
Ranch Hand
Posts: 423
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
really battling with the logic in this for loop exercise

Prompt the user for the number of numbers they want to enter. Read in each of the number. When all the number have been entered display: the average, the highest number, the number that were divisible by 3, and the total



what i cant work out is how to store each user input in a variable within the loop and not allowed to use lists

any push in the right direction would greatly be appreciated
 
author & internet detective
Posts: 38918
686
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jon,
Start with total. That's the easiest. Could you create a variable outside the loop and update it each time you go through the loop to keep a running total?

Once that works, you can start to think about what variables you would need for the other things in the assignment.
 
jon ninpoja
Ranch Hand
Posts: 423
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi jeanne

yes i realise that i dont need every value stored in a variable
i have just created a total
and total = total + numberAdded
or total += numberAdded

trying to work out how to get the highest value in the numbers now
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!