• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

find the smallest of several integers

 
Nnamdi Obiamalu
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write a java application that finds the smallest of several integers. Prompt the user for the number of integers that will be input, then prompt the user for that number of integers. Evaluate the integers to determine the smallest value.

Run the program to test for 3 numbers
-- 50, 10, 100

Run the program a second time to test for 5 input number;
-- 7, -2, 0, 15, 5

Please I really don't understand this?
 
fred rosenberger
lowercase baba
Posts: 12751
51
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what have you got so far? as general advice, you want to only write small pieces at a time. So, first, you want to write the program that prompts for input - and that's it. it's not actually going to GET the input yet, you just want it to ask for the input.

Once you have that working, THEN try and GET the input.

Keep adding a tiny pieces at a time.
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
Oceas Anderson
Greenhorn
Posts: 17
Android Chrome Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The requirements are pretty straight forward but perhaps a more detailed console output on what the final product can look like will help clarify for you.


Console
----------
"How many integers are you inputting?"
3 <- Record number of expected numbers
40<- Record each integer input most likely stored in an array or another collection type
20<- Record each integer input most likely stored in an array or another collection type
79<- Record each integer input most likely stored in an array or another collection type

"The smallest integer is 20" <- Output to the user the smallest integer that they inputted


 
Campbell Ritchie
Marshal
Posts: 64705
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not at all convinced that is the way I would do that. You can do largest, smallest, average or total without recording the numbers anywhere.
 
Oceas Anderson
Greenhorn
Posts: 17
Android Chrome Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:I am not at all convinced that is the way I would do that. You can do largest, smallest, average or total without recording the numbers anywhere.



Good point, when writing up the example it just seemed to be the simplest at the time but I imagine a cleaner solution would be to store the first value inputted and then compare the value of the next system input to the current recorded smallest value and replace it if it is a smaller value.
 
Campbell Ritchie
Marshal
Posts: 64705
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree. You can do the same for maximum value, too. But let's not give too much detail because OP will learn much better if we let them work it out by themselves.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!