- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Enter the shape\n1.Rectangle\n2.Triangle");
- int option = scanner.nextInt();
- switch (option) {
- case 1:
- System.out.println("Enter the length and breadth:");
- Shape.value1 = scanner.nextDouble();
- Shape.value2 = scanner.nextDouble();
- Shape.Rectangle rectangle = new Shape.Rectangle();
- double rectangleArea = rectangle.computeRectangleArea();
- System.out.printf("Area of rectangle is %.2f\n", rectangleArea);
- break;
- case 2:
- System.out.println("Enter the base and height:");
- Shape.value1 = scanner.nextDouble();
- Shape.value2 = scanner.nextDouble();
- Shape.Triangle triangle = new Shape.Triangle();
- double triangleArea = triangle.computeTriangleArea();
- System.out.printf("Area of triangle is %.2f\n", triangleArea);
- break;
- default:
- System.out.println("Invalid choice");
- }
- }
- }
[text] Main.java
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: