KnowledgeBoat Logo

Computer Applications

Write a program in Java to calculate and display the hypotenuse of a Right-Angled Triangle by taking perpendicular and base as inputs.

Hint: h = √p2 + b2

Java

Java Math Lib Methods

183 Likes

Answer

import java.util.Scanner;

public class KboatHypotenuse
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter Perpendicular: ");
        double p = in.nextDouble();
        System.out.print("Enter Base: ");
        double b = in.nextDouble();
        
        double h = Math.sqrt(Math.pow(p, 2) + Math.pow(b, 2));
        
        System.out.println("Hypotenuse = " + h);
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of Write a program in Java to calculate and display the hypotenuse of a Right-Angled Triangle by taking perpendicular and base as inputs. Hint: h = √p 2 + b 2

Answered By

72 Likes


Related Questions