Advertisement
veronikaaa86

07. Area of Figures

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