Advertisement
veronikaaa86

07. Area of Figures

Sep 17th, 2022
1,157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P07AreaOfFigures {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String typeFigure = scanner.nextLine();
  8.  
  9.         double area = 0;
  10.         if (typeFigure.equals("square")) {
  11.             double side = Double.parseDouble(scanner.nextLine());
  12.  
  13.             area = side * side;
  14.  
  15.         } else if (typeFigure.equals("rectangle")) {
  16.             double length = Double.parseDouble(scanner.nextLine());
  17.             double width = Double.parseDouble(scanner.nextLine());
  18.  
  19.             area = length * width;
  20.  
  21.         } else if (typeFigure.equals("circle")) {
  22.             double radius = Double.parseDouble(scanner.nextLine());
  23.  
  24.             area = Math.PI * radius * radius;
  25.  
  26.         } else if (typeFigure.equals("triangle")) {
  27.             double base = Double.parseDouble(scanner.nextLine());
  28.             double height = Double.parseDouble(scanner.nextLine());
  29.  
  30.  
  31.         }
  32.  
  33.         System.out.printf("%.3f", area);
  34.     }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement