Java Code/Program - Calculate Hypotenuse Using Pythagorean Theorem

by matt392 in Circuits > Software

8813 Views, 3 Favorites, 0 Comments

Java Code/Program - Calculate Hypotenuse Using Pythagorean Theorem

Pythagorean-Theorem.jpeg

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 test 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
{
    public static void main(String[] args) 
    {
        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