Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AreaOfFigures {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String figures = scanner.nextLine();
- if (figures.equals("square")) {
- double side = Double.parseDouble(scanner.nextLine());
- System.out.println(side * side);
- } else if (figures.equals("rectangle")) {
- double base = Double.parseDouble(scanner.nextLine());
- double height = Double.parseDouble(scanner.nextLine());
- System.out.println(base * height);
- } else if (figures.equals("circle")) {
- double radius = Double.parseDouble(scanner.nextLine());
- System.out.println(Math.PI * radius * radius);
- } else if (figures.equals("triangle")) {
- double base = Double.parseDouble(scanner.nextLine());
- double height = Double.parseDouble(scanner.nextLine());
- System.out.println(base * height / 2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement