java program to find the hypotenuse and display by taking perpendicular and base as inputs
Answers
Question:-
➡ Write a java program to find and display the hypotenuse by taking perpendicular and base as input.
Program:-
This is written in Java.
import java.util.*;
class Hypotenuse
{
public static void main(String s[])
{
Scanner sc=new Scanner(System.in);
double p, b, h;
System.out.print("Enter the perpendicular: ");
p=sc.nextDouble();
System.out.print("Enter the base: ");
b=sc.nextDouble();
h=Math.sqrt(p*p+b*b);
System.out.println("Hypotenuse of the triangle is: "+h);
}
}
import java.util.Scanner;
public class Hypotenuse {
public static void main(String[ ] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter :\nPerpendicular - ");
double perpendicular = sc.nextDouble( );
System.out.print("Base - ");
double base = sc.nextDouble( );
System.out.println("Hypotenuse of the triangle - " +
Math.sqrt(perpendicular * perpendicular + base * base));
}
}