Showing posts with label Area of the ractangle. Show all posts
Showing posts with label Area of the ractangle. Show all posts

 

Write a Java program to find the Area of the Circle, Rectangle and Triangle.




PROGRAM :

import java.util.*;
class area1
{
  
  public static void main(String[] args) throws InputMismatchException
  {
   Scanner sc = new Scanner(System.in);
   double area;
   
   System.out.println("Main Menu");

   System.out.println("1. Circle");

   System.out.println("2. Ractangle");

   System.out.println("3. Triangle");

   System.out.println("Enter your choice(1,2,3) : ");

   int ch;
   ch=sc.nextInt();

   switch(ch)
   {
    case 1:
         System.out.print("Enter the radius : ");
         double r=sc.nextDouble();

         area=r*r*3.14;
         System.out.println("\nThe area of Circle is : "+area);
         break;

    case 2:
         System.out.print("Enter the length : ");
         double l=sc.nextDouble();

         System.out.print("Enter the width :  ");
         double w=sc.nextDouble();

         area=l*w;
         System.out.println("\nThe area of Ractangle is : "+area);
         break;

    case 3:
         System.out.println("Enter sides of triangle : ");

         System.out.print("Enter side1 : ");
         double a=sc.nextDouble();

         System.out.print("Enter side2 : ");
         double b=sc.nextDouble();

         System.out.print("Enter side3 : ");
         double c=sc.nextDouble();

         double s=(a+b+c)/2;
         area=Math.sqrt(s*(s-a)*(s-b)*(s-c));

         System.out.println("\nThe area of Triangle is : "+area);
         break;

    default:
         System.out.println("Wrong choice !!!");
         break;
    }
  }
}