• Post Reply Bookmark Topic Watch Topic
  • New Topic

find the smallest of several integers  RSS feed

 
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
Bartender
Posts: 12565
49
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: 3271
82
  • 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: 56584
172
  • 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: 56584
172
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!