User Tools

Site Tools


cs175:find_largest_of_five_integers

Find largest of five input integers


We worked on an algorithm to find the largest of five numbers. A possible algorithm is shown below:

   Take one number at a time out of the container.

   Assume that the first number is the largest.

   If the second number is greater than the largest,
   the largest is now the second number.

   If the third number is greater than the largest,
   the largest is now the third number.

   If the fourth number is greater than the largest,
   the largest is now the fourth number.

   If the fifth number is greater than the largest,
   the largest is now the fifth number.

In drjava, write LargestOfFive.java that does the following:

  • Use Scanner input to input 5 int values and store the values in five int variables
  • Use if statements to find the largest among the five integers.
  • Output the value of the largest among the five integers.

Sample input/output:

   Input 5 integers, space separated:
   44 33 22 66 99
   
   The largest is: 99

Link to source code

Link to program using alternative algorithm


cs175/find_largest_of_five_integers.txt · Last modified: 2014/10/13 14:22 by jchung

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki