Advertisement
Spocoman

07. Area of Figures

Aug 25th, 2024
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 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.         String figures = scanner.nextLine();
  7.  
  8.         if (figures.equals("square")) {
  9.             double side = Double.parseDouble(scanner.nextLine());
  10.             System.out.println(side * side);
  11.         } else if (figures.equals("rectangle")) {
  12.             double base = Double.parseDouble(scanner.nextLine());
  13.             double height = Double.parseDouble(scanner.nextLine());
  14.             System.out.println(base * height);
  15.         } else if (figures.equals("circle")) {
  16.             double radius = Double.parseDouble(scanner.nextLine());
  17.             System.out.println(Math.PI * radius * radius);
  18.         } else if (figures.equals("triangle")) {
  19.             double base = Double.parseDouble(scanner.nextLine());
  20.             double height = Double.parseDouble(scanner.nextLine());
  21.             System.out.println(base * height / 2);
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement