Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AreaCalculator {
- static Scanner sc = new Scanner(System.in);
- public static void main(String[] args)
- {
- System.out.println("Do you want to calculate the area of a square, rectangle, circle or triangle?");
- double square;
- double triangle;
- double rectangle;
- double circle;
- String input = sc.nextLine();
- if ("triangle".equals(input.toLowerCase()))
- {
- double base;
- double height;
- System.out.print("Enter the triangles base: ");
- base = sc.nextDouble();
- System.out.print("Enter the triangle's height: ");
- height = sc.nextDouble();
- double Area = (base * height) / 2;
- System.out.println("The area of your triangle is: " + Area);
- }
- if ("square".equals(input.toLowerCase()))
- {
- double sides;
- System.out.print("Enter the lenght of the square's side: ");
- sides = sc.nextDouble();
- double Area = sides * sides;
- System.out.println("The area of your square is: " + Area);
- }
- if ("rectangle".equals(input.toLowerCase()))
- {
- double base;
- double height;
- System.out.print("Enter the rectangle's base: ");
- base = sc.nextDouble();
- System.out.print("Enter the rectangle's height: ");
- height = sc.nextDouble();
- double Area = base * height;
- System.out.println("The area of your rectangle is: " + Area);
- }
- if ("circle".equals(input.toLowerCase()))
- {
- double radius;
- System.out.print("Please note: This calculator uses 10 decimals of Pi.\nEnter the circle's radius: ");
- radius = sc.nextDouble();
- double Area = 3.1415926535 * radius * radius;
- System.out.println("The area of your circle is: " + Area);
- }
- else
- {
- System.out.println("Oops! Looks like you spelled something wrong!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment