desislava_topuzakova

07. Area of Figures

Sep 19th, 2021
1,075
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Figure {
  4.     public static void main(String[] args) {
  5.  
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         String figure = scanner.nextLine();
  9.  
  10.         if(figure.equals("square")){
  11.             double side = Double.parseDouble(scanner.nextLine());
  12.  
  13.             double area = side * side;
  14.  
  15.             System.out.printf("%.3f", area);
  16.         }
  17.         else if (figure.equals("rectangle")){
  18.             double sideA = Double.parseDouble(scanner.nextLine());
  19.             double sideB = Double.parseDouble(scanner.nextLine());
  20.  
  21.             double area = sideA * sideB;
  22.  
  23.             System.out.printf("%.3f" , area);
  24.         }
  25.         else if (figure.equals("circle")){
  26.             double radius = Double.parseDouble(scanner.nextLine());
  27.  
  28.             double area = Math.PI * (Math.pow(radius, 2));
  29.  
  30.             System.out.printf("%.3f", area);
  31.         }
  32.         else if(figure.equals("triangle")){
  33.  
  34.             Double side = Double.parseDouble(scanner.nextLine());
  35.             Double height = Double.parseDouble(scanner.nextLine());
  36.  
  37.             double area = (side / 2) * height;
  38.  
  39.             System.out.printf("%.3f", area);
  40.         }
  41.  
  42.     }
  43. }
RAW Paste Data