This is a simple Java program that calculates the hypotenuse of a right-angled triangle using the Pythagorean theorem:
[ \text{hypotenuse} = \sqrt{\text{side1}^2 + \text{side2}^2} ]
- The program prompts the user to enter two sides of a right-angled triangle.
- It calculates the hypotenuse using the formula ( \text{hypotenuse} = \sqrt{x^2 + y^2} ).
- Finally, it displays the result.
- Java Development Kit (JDK)
- A command-line terminal or any Java IDE like IntelliJ IDEA, Eclipse, etc.
-
Compile the Program
Open the terminal or command prompt, navigate to the directory where your file is located, and run:javac Main.java
-
Run the Program
After compiling, run the program with:java Main
-
Enter Inputs
- You will be prompted to enter the values for two sides of a right-angled triangle.
- The program will then display the calculated hypotenuse.
Enter side x: 3
Enter side y: 4
The hypotenuse is: 5.0