RightTriangleWithLoop Program
Description
This program is the enhanced version of the previous program.It uses a method to calculate and return the hypotenuse of the right triangle.
In the main() method, it uses a loop to accept the user input and call the method until the user chooses not to.
It also validates the user input.
Associated Concepts:
Method
Global and local variables
Calling method in a loop
Global and local variables
Calling method in a loop
Algorithm:
Declare and create keyboard as a global variable so it is available to
all the methods in the program.
main method:
hypotenuse method definition:
main method:
Declare local variables to represent
side 1, side 2, and side 3 of right triangle
Use a loop to input side 1 and side 2 from the keyboard until the user enters -1 as side 1
Call hypotenuse method and pass side1 and side2 as arguments
Print the result
Use a loop to input side 1 and side 2 from the keyboard until the user enters -1 as side 1
Call hypotenuse method and pass side1 and side2 as arguments
Print the result
hypotenuse method definition:
Calculate and return side 3 based on the parameters passed
by the caller