Advertisement
Guest User

Area of figures

a guest
Jun 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 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 figure = scanner.nextLine();
  7.         if(figure.equals("square")){
  8.             System.out.println("The figure is square!" + " " + "Enter the length of the side: ");
  9.             double squareSide = Double.parseDouble(scanner.nextLine());
  10.             double squareArea = squareSide*squareSide;
  11.             System.out.printf("%.3f",squareArea);
  12.         }
  13.         if(figure.equals("rectangle")){
  14.             System.out.println("The figure is rectangle!" + " " + "Enter the length of the first side: ");
  15.             double rectangleSideOne = Double.parseDouble(scanner.nextLine());
  16.             System.out.println("Enter the length of the second side: ");
  17.             double rectangleSideTwo = Double.parseDouble(scanner.nextLine());
  18.             double rectangleArea = rectangleSideOne * rectangleSideTwo;
  19.             System.out.printf("%.3f",rectangleArea);
  20.         }
  21.         if(figure.equals("circle")){
  22.             double radius = Double.parseDouble(scanner.nextLine());
  23.             double circleArea = Math.PI*radius*radius;
  24.             System.out.printf("%.3f",circleArea);
  25.         }
  26.         if(figure.equals("triangle")){
  27.             double side = Double.parseDouble(scanner.nextLine());
  28.             double h = Double.parseDouble(scanner.nextLine());
  29.             double triArea = (side*h)/2;
  30.             System.out.printf("%.3f",triArea);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement