# Java Code/Program - Calculate Hypotenuse Using Pythagorean Theorem

153

Please find below and attached a short Java program that takes 2 numbers inputted from the keyboard and calculates the hypotenuse using the Pythagorean Theorem.
+++++++++++++++++++++++++++++++++++

// Matt R - Java program
// Created using BlueJ IDE www.BlueJ.org

// Import Scanner class
import java.util.Scanner;
// Import Math class
import java.lang.Math;

public class MattPythagoreanTheorem
{
System.out.println("Enter first side triangle: ");
// Create Scanner object for keyboard input called "alpha"
Scanner alpha = new Scanner(System.in);
// Put 1st double number into variable bravo
double bravo = alpha.nextDouble();
System.out.println("Enter 2nd side of triangle: ");
// Put 2nd double number into variable "charlie"
double charlie = alpha.nextDouble();

// Calculate Pythagorean Theorem put into variable "delta"
double delta = (Math.pow(bravo,2)) + (Math.pow(charlie,2));
System.out.println("1st number entered: " + bravo);
System.out.println("2nd number entered: " + charlie);
System.out.println("Pythagorean Theorem (a^2 + b^2 = c^2) result: " + delta);

// Close the Scanner object that takes input from keyboard
alpha.close();
} // end of public static void main(String[] args)

} // end of public class MattUsingForLoop

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.