KnowledgeBoat Logo

Computer Applications

Write a program in Java to input perpendicular and base of a right angle triangle using the Scanner class. Calculate and display its hypotenuse using the formula given below:
h = √(p2 + b2)

Java

Input in Java

15 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);
    }
}

Output

BlueJ output of Write a program in Java to input perpendicular and base of a right angle triangle using the Scanner class. Calculate and display its hypotenuse using the formula given below: h = √(p 2 + b 2 )

Answered By

9 Likes


Related Questions