SHARE
TWEET

areaOfFigures

yovkovbpfps Mar 26th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Nums100 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String figType = scanner.nextLine();
  7.  
  8.         double area = 0;
  9.         switch (figType) {
  10.             case "square": {
  11.                 double a = Double.parseDouble(scanner.nextLine());
  12.                 area = a * a;
  13.                 break;
  14.             }
  15.             case "rectangle": {
  16.                 double a = Double.parseDouble(scanner.nextLine());
  17.                 double b = Double.parseDouble(scanner.nextLine());
  18.                 area = a * b;
  19.                 break;
  20.             }
  21.             case "circle": {
  22.                 double r = Double.parseDouble(scanner.nextLine());
  23.                 area = Math.PI * r * r;
  24.                 break;
  25.             }
  26.             case "triangle": {
  27.                 double side = Double.parseDouble(scanner.nextLine());
  28.                 double height = Double.parseDouble(scanner.nextLine());
  29.                 area = (side * height)/2;
  30.                 break;
  31.  
  32.  
  33.             }
  34.  
  35.  
  36.  
  37.         }
  38.         System.out.printf("%.3f", area);
  39.         }
  40.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top