borkins

13a. Area of Figures

Mar 24th, 2017
145
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 _13a_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.         if (figure.equals("square"))
  17.         {
  18.             area = Math.pow(Double.parseDouble(scan.nextLine()), 2);
  19.         }
  20.         else if (figure.equals("rectangle"))
  21.         {
  22.             double a = Double.parseDouble(scan.nextLine());
  23.             double b = Double.parseDouble(scan.nextLine());
  24.             area = a * b;
  25.         }
  26.         else if (figure.equals("circle"))
  27.         {
  28.             area = Math.pow(Double.parseDouble(scan.nextLine()), 2) * Math.PI;
  29.            
  30.         }
  31.         else if (figure.equals("triangle"))
  32.         {
  33.             double c = Double.parseDouble(scan.nextLine());
  34.             double h = Double.parseDouble(scan.nextLine());
  35.             area = c * h / 2d;
  36.         }
  37.         System.out.printf("%.3f", area);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment