Advertisement
Angel_Kalinkov

SimpleConditionalStatements-AreaOfFigures_AngelKalinkov

Jan 25th, 2018
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class AreaOfFigures {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String geometricShape = scanner.nextLine().toLowerCase();
  8.  
  9.         switch (geometricShape) {
  10.             case "square":
  11.                 double side = Double.parseDouble(scanner.nextLine());
  12.                 System.out.printf("%.3f%n", (side * side));
  13.                 break;
  14.             case "rectangle":
  15.                 double length = Double.parseDouble(scanner.nextLine());
  16.                 double width = Double.parseDouble(scanner.nextLine());
  17.                 System.out.printf("%.3f%n", (length * width));
  18.                 break;
  19.             case "circle":
  20.                 double radius = Double.parseDouble(scanner.nextLine());
  21.                 System.out.printf("%.3f%n", (Math.PI * radius * radius));
  22.                 break;
  23.             case "triangle":
  24.                 double base = Double.parseDouble(scanner.nextLine());
  25.                 double hight = Double.parseDouble(scanner.nextLine());
  26.                 System.out.printf("%.3f%n", (base * hight / 2));
  27.                 break;
  28.             default:
  29.                 System.out.println("Unknown geometric shape.");
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement