Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.  * Created by Atanas on 17/01/2017.
  5.  */
  6. public class p13_Sharea {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         String shape = scanner.nextLine();
  11.  
  12.         if (shape.equals("square")){
  13.             double a = Double.parseDouble(scanner.nextLine());
  14.             double b = a * a;
  15.             System.out.printf("%.3f%n", b);
  16.         } else if (shape.equals("circle")){
  17.             double a = Double.parseDouble(scanner.nextLine());
  18.             double b = a * a * Math.PI;
  19.             System.out.printf("%.3f%n", b);
  20.         } else if (shape.equals("rectangle")){
  21.             double a = Double.parseDouble(scanner.nextLine());
  22.             double b = Double.parseDouble(scanner.nextLine());
  23.             double c = a * b;
  24.             System.out.printf("%.3f%n", c);
  25.         } else if (shape.equals("triangle")){
  26.             double a = Double.parseDouble(scanner.nextLine());
  27.             double b = Double.parseDouble(scanner.nextLine());
  28.             double c = (a * b) / 2;
  29.             System.out.printf("%.3f%n", c);
  30.         }
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement