N. Achyut java,Java Introductions Procedural method to calculate the area of a Circle, Square, Rectangle and Sphere

Procedural method to calculate the area of a Circle, Square, Rectangle and Sphere

Procedural method to calculate the area of a Circle, Square, Rectangle and Sphere

Procedural method to calculate the area of a Circle, Square, Rectangle and Sphere

Write both procedural to calculate the area of a
a) Circle
b) Square
c) Rectangle
d) Sphere

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package assignments;

/**
 *
 * @author achyut1324
 */
public class QS5Procedural {
    public static void main(String[] args) {
        System.out.println("the area of circle is "+area()+"n The area of Square is "+square() +
                "n the area of Rectangle is : "+rectangle()+ "n The area of Sphere is: "+sphere());
    }
   public static double area(){
       double r = 5;
       return Math.PI*r*r;
   }
   public static double square(){
       double l= 5;
       return l*l;
   }
   public static double rectangle(){
       double l=10;
       double b= 15;
       return l*b;
   }
   public static double sphere(){
       double r = 5;
       return 4*Math.PI*r*r;
   }
}

Output:

the area of circle is 78.53981633974483
The area of Square is 25.0
the area of Rectangle is : 150.0
The area of Sphere is: 314.1592653589793
BUILD SUCCESSFUL (total time: 0 seconds)

Related Post