Advertisement
Guest User

Area of Figures

a guest
Jan 20th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 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 figure = scanner.nextLine();
  8.  
  9.         if (figure.equals("square")) {
  10.             double lengths = Double.parseDouble(scanner.nextLine());
  11.             System.out.printf("%.3f",(lengths * lengths));
  12.         } else if (figure.equals("rectangle")) {
  13.             double length1 = Double.parseDouble(scanner.nextLine());
  14.             double length2 = Double.parseDouble(scanner.nextLine());
  15.             System.out.printf("%.3f",(length1 * length2));
  16.         } else if (figure.equals("circle")) {
  17.             double radius = Double.parseDouble(scanner.nextLine());
  18.             System.out.printf("%.3f", (Math.PI * radius*radius));
  19.         } else if (figure.equals("triangle")) {
  20.             double lengtht = Double.parseDouble(scanner.nextLine());
  21.             double height = Double.parseDouble(scanner.nextLine());
  22.             System.out.printf("%.3f", (lengtht * height/2));
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement