Advertisement
desislava_topuzakova

Areas

May 4th, 2018
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class Areas {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         DecimalFormat df = new DecimalFormat("#.###");
  8.         String type = scanner.nextLine();
  9.         if (type.equals("square")){
  10.             double side = Double.parseDouble(scanner.nextLine());
  11.             double area = side * side;
  12.             System.out.printf(df.format(area));
  13.  
  14.         }else if (type.equals("rectangle")){
  15.             double sideA = Double.parseDouble(scanner.nextLine());
  16.             double sideB = Double.parseDouble(scanner.nextLine());
  17.             double area = (sideA * sideB);
  18.             System.out.printf(df.format(area));
  19.         }else if (type.equals("circle")){
  20.             double radius = Double.parseDouble(scanner.nextLine());
  21.             double area = Math.PI * radius * radius;
  22.             System.out.printf(df.format(area));
  23.         }else if (type.equals("triangle")){
  24.             double sideB = Double.parseDouble(scanner.nextLine());
  25.             double h = Double.parseDouble(scanner.nextLine());
  26.             double area = (sideB * h) / 2;
  27.  
  28.             System.out.printf("%.3f",area);
  29.  
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement