Advertisement
veronikaaa86

07. Area of Figures

May 20th, 2023
929
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 1 0
  1. package conditionalStatementsLab;
  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 a = Double.parseDouble(scanner.nextLine());
  14.             area = a * a;
  15.  
  16.         } else if (typeFigure.equals("rectangle")) {
  17.             double a = Double.parseDouble(scanner.nextLine());
  18.             double b = Double.parseDouble(scanner.nextLine());
  19.  
  20.             area = a * b;
  21.  
  22.         } else if (typeFigure.equals("circle")) {
  23.             double r = Double.parseDouble(scanner.nextLine());
  24.             area = Math.PI * r * r;
  25.  
  26.         } else if (typeFigure.equals("triangle")) {
  27.             double a = Double.parseDouble(scanner.nextLine());
  28.             double ha = Double.parseDouble(scanner.nextLine());
  29.             area = (a * ha) / 2;
  30.         }
  31.  
  32.         System.out.printf("%.3f", area);
  33.     }
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement