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 figures = scanner.nextLine();
- if (figures.equals("square")) {
- double a = Double.parseDouble(scanner.nextLine());
- //System.out.println(a*a);
- double s = a*a;
- System.out.printf("%.3f", s);
- } else if (figures.equals("rectangle")) {
- double a = Double.parseDouble(scanner.nextLine());
- double b = Double.parseDouble(scanner.nextLine());
- //System.out.println(a*b);
- double s = a*b;
- System.out.printf("%.3f", s);
- } else if (figures.equals("circle")) {
- double r = Double.parseDouble(scanner.nextLine());
- //System.out.println(Math.PI*r*r);
- double s = Math.PI*r*r;
- System.out.printf("%.3f", s);
- } else if (figures.equals("triangle")) {
- double a = Double.parseDouble(scanner.nextLine());
- double h = Double.parseDouble(scanner.nextLine());
- //System.out.println(a*h/2);
- double s = a*h/2;
- System.out.printf("%.3f", s);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement