Friday, October 31, 2014

Java Shapes Pro



Java Program to Calculate Area of Rectangle

import java.util.Scanner;
class AreaOfRectangle 
{
 public static void main (String[] args)
{
      Scanner scanner = new Scanner(System.in);
      System.out.println("Enter the length of Rectangle:");
      double length = scanner.nextDouble();
      System.out.println("Enter the width of Rectangle:");
      double width = scanner.nextDouble();
      Area = length*width;
      double area = length*width;
      System.out.println("Area of Rectangle is:"+area);
   }
}

Java program to calculate area of Square

import java.util.Scanner;
class SquareAreaDemo 
{
 public static void main (String[] args)
 {
       System.out.println("Enter Side of Square:");
       Scanner scanner = new Scanner(System.in);
       double side = scanner.nextDouble();
       double area = side*side; 
       System.out.println("Area of Square is: "+area);
   }
}

Java program to calculate area of Triangle

import java.util.Scanner;
class AreaTriangleDemo 
{
public static void main(String args[]) 
{   
      Scanner scanner = new Scanner(System.in);
                System.out.println("Enter the width of the Triangle:");
      double base = scanner.nextDouble();
                System.out.println("Enter the height of the Triangle:");
      double height = scanner.nextDouble();
                Area = (width*height)/2
      double area = (base* height)/2;
      System.out.println("Area of Triangle is: " + area);      
   }
}

Java Program to calculate area and circumference of circle

import java.util.Scanner;
class CircleDemo
{
 static Scanner sc = new Scanner(System.in);
 public static void main(String args[])
{
      System.out.print("Enter the radius: ");
      double radius = sc.nextDouble();
      Area = PI*radius*radius
      double area = Math.PI * (radius * radius);
      System.out.println("The area of circle is: " + area);
      Circumference = 2*PI*radius
      double circumference= Math.PI * 2*radius;
      System.out.println( "The circumference of the circle is:"+circumference) ;
   }
}

 

No comments:

Post a Comment