Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AreaFigures {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String type = scanner.nextLine();
- double area =0.0;
- if (type.equals("square")){
- double a = Double.parseDouble(scanner.nextLine());
- area = a * a;
- }else if (type.equals("rectangle")) {
- double a = Double.parseDouble(scanner.nextLine());
- double b = Double.parseDouble(scanner.nextLine());
- area = a * b;
- }else if (type.equals("circle")){
- double r = Double.parseDouble(scanner.nextLine());
- area = Math.PI*r*r;
- }else if (type.equals("triangle"));{
- double a = Double.parseDouble(scanner.nextLine());
- double h = Double.parseDouble(scanner.nextLine());
- area = a*h/2;
- }
- System.out.printf("%.3f", area);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement