Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Title: Lab 5
- Author: Terry Weiss
- Date: 9/29/15
- Course & Section: CSC 109-103W
- Description: This program will will prompt the user for three numbers and displays them in ascending order.
- Initial Algorithm
- Get 3 numbers
- Add the smallest number to a list
- Add the second smallest number to a list
- Add the remaining number to a list
- Display the list in ascending order
- Data Requirements:
- (int) number1 – This is the first number given by the user.
- (int) number2 – This is the second number given by the user.
- (int) number3 – This is the third number given by the user.
- (int[]) list – This is the list of numbers in ascending order.
- (Scanner) user_input – This is the object that holds the user’s input.
- Formulas: None
- Refined Algorithm
- Get 3 numbers
- IF number1 < number2 AND number1 < number3 THEN
- Put number1 first in list
- IF number2 < number3 THEN
- Put number2 second in list
- Put number3 third in list
- ELSE
- Put number3 second in list
- Put number2 third in list
- END IF
- ELSE IF number2 < number1 AND number2 < number3 THEN
- Put number2 first in list
- IF number1 < number3 THEN
- Put number1 second in list
- Put number3 third in list
- ELSE
- Put number3 second in list
- Put number1 third in list
- END IF
- ELSE
- Put number3 first in list
- IF number1 < number2 THEN
- Put number1 second in list
- Put number2 third in list
- ELSE
- Put number2 second in list
- Put number1 third in list
- END IF
- END IF
- Display numbers from list in ascending order
Advertisement
Add Comment
Please, Sign In to add comment