Advertisement
borkins

13b. Area of Figures

Mar 24th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. /**
  2.  * Project: Simple_Conditions - created by borkins on 2017-03-25.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class _13b_AreaOfFigures
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         Scanner scan = new Scanner(System.in);
  12.        
  13.         String figure = scan.nextLine().toLowerCase();
  14.         double area = 0d;
  15.        
  16.         switch (figure)
  17.         {
  18.             case "square":
  19.                 area = Math.pow(Double.parseDouble(scan.nextLine()), 2);
  20.                 break;
  21.             case "rectangle":
  22.                 double a = Double.parseDouble(scan.nextLine());
  23.                 double b = Double.parseDouble(scan.nextLine());
  24.                 area = a * b;
  25.                 break;
  26.             case "circle":
  27.                 area = Math.pow(Double.parseDouble(scan.nextLine()), 2) * Math.PI;
  28.                 break;
  29.             case "triangle":
  30.                 double c = Double.parseDouble(scan.nextLine());
  31.                 double h = Double.parseDouble(scan.nextLine());
  32.                 area = c * h / 2d;
  33.                 break;
  34.         }
  35.         System.out.printf("%.3f", area);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement