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 figure = scanner.nextLine();
- if(figure.equals("square")){
- System.out.println("The figure is square!" + " " + "Enter the length of the side: ");
- double squareSide = Double.parseDouble(scanner.nextLine());
- double squareArea = squareSide*squareSide;
- System.out.printf("%.3f",squareArea);
- }
- if(figure.equals("rectangle")){
- System.out.println("The figure is rectangle!" + " " + "Enter the length of the first side: ");
- double rectangleSideOne = Double.parseDouble(scanner.nextLine());
- System.out.println("Enter the length of the second side: ");
- double rectangleSideTwo = Double.parseDouble(scanner.nextLine());
- double rectangleArea = rectangleSideOne * rectangleSideTwo;
- System.out.printf("%.3f",rectangleArea);
- }
- if(figure.equals("circle")){
- double radius = Double.parseDouble(scanner.nextLine());
- double circleArea = Math.PI*radius*radius;
- System.out.printf("%.3f",circleArea);
- }
- if(figure.equals("triangle")){
- double side = Double.parseDouble(scanner.nextLine());
- double h = Double.parseDouble(scanner.nextLine());
- double triArea = (side*h)/2;
- System.out.printf("%.3f",triArea);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement