Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ExamPreparation {
  4. public static void main(String[] args) {
  5.  
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. String typeGeometricForm = scanner.nextLine();
  9.  
  10. if ("square".equals(typeGeometricForm)) {
  11. double number = Double.parseDouble(scanner.nextLine());
  12. double result = number * number;
  13. System.out.printf("%.3f", result);
  14. } else if ("rectangle".equals(typeGeometricForm)) {
  15. double a = Double.parseDouble(scanner.nextLine());
  16. double b = Double.parseDouble(scanner.nextLine());
  17. double result = a * b;
  18. System.out.printf("%.3f", result);
  19. } else if ("circle".equals(typeGeometricForm)) {
  20. double r = Double.parseDouble(scanner.nextLine());
  21. double result = Math.PI * r*r;
  22. System.out.printf("%.3f", result);
  23. } else if ("triangle".equals(typeGeometricForm)) {
  24. double a = Double.parseDouble(scanner.nextLine());
  25. double b = Double.parseDouble(scanner.nextLine());
  26. double result = (a * b) / 2;
  27. System.out.printf("%.3f", result);
  28. }
  29.  
  30. }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement