RightTriangle Program
Description
This program uses a method to calculate and return the hypotenuse of the right triangle.It also demonstrates the concepts of global and local variables.
Associated Concepts:
Method
Global and local variables
Global and local variables
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
Input side 1 and side 2 from the keyboard
Call hypotenuse method and pass side1 and side2 as arguments, and use side3 to hold the returned value
Print the result
Input side 1 and side 2 from the keyboard
Call hypotenuse method and pass side1 and side2 as arguments, and use side3 to hold the returned value
Print the result
hypotenuse method definition:
Declare local variable s3 to represent
side 3 of the right triangle
Calculate side 3 based on the parameters passed by the caller
Return the result
Calculate side 3 based on the parameters passed by the caller
Return the result