Advertisement
Guest User

Hypotenuse3

a guest
Nov 14th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. package bg.unwe;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Hypotenuse3 {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         System.out.print("Enter a: ");
  11.         int a = scanner.nextInt();
  12.  
  13.         if (a <= 0) {
  14.             System.out.println("The side A cannot be less than or equal to zero");
  15.             return;
  16.         }
  17.  
  18.         System.out.print("Enter b: ");
  19.         int b = scanner.nextInt();
  20.  
  21.         if (b <= 0) {
  22.             System.out.println("The side B cannot be less than or equal to zero");
  23.             return;
  24.         }
  25.  
  26.         if (a == b) {
  27.             System.out.println("This is an isosceles triangle");
  28.         }
  29.  
  30.         double c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
  31.         System.out.printf("The length of the hypotenuse is %.2f\n", c);
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement