• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

find the smallest of several integers

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
lowercase baba
Posts: 13073
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
Greenhorn
Posts: 17
Android Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Marshal
Posts: 76447
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76447
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic