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