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