# Java Program to Find Surface Area and Volume of Cylinder

• Write a java program to calculate the volume and surface area of sphere.

In this Java program, We have to find the volume and total surface of a cylinder, given the height and base radius of cylinder.

Volume of Cylinder
The volume of a right circular cylinder is defined as the amount of three dimensional space occupied by the cylinder or the storage capacity of a cylinder. To calculate the volume of a cylinder, we need radius of base height of cylinder.
Volume of right circular cylinder = Base area x Height
As base of cylinder is circular, Base Area = ΠR2
Total Surface Area of Cylinder
Surface area of cylinder is the number of square units that will exactly cover the outer surface of a cone. There are three surfaces in a cylinder, one curved and two circular bases. Total surface area of cylinder is the sum of the area of both circular bases and area of curved surface.
• Base area of cylinder = ΠR2
• Curved surface area of cone = 2ΠRH
Total surface area of cone = 2XBase area + Curved area
= 2ΠR2 + 2ΠRH
= 2ΠR(R + H)
NOTE : Π = 3.141

## Java program to find the volume and surface area of cylinder

In this java program, we first take base radius and height of cylinder as input from user and then calculate volume and surface area using above mentioned mathematical formulae.

```package com.tcc.java.programs;

import java.util.Scanner;

/**
* Java Program to find volume and surface area of Cylinder
*/
public class VolumeOfCylinder {

public static void main(String[] args) {
Scanner scanner;
scanner = new Scanner(System.in);
// Take input from user

System.out.println("Enter Height of Cylinder");
height = scanner.nextDouble();

/*
* Total surface area of Cylinder = 2 X PI X Radius X (Radius + Height)
*/

/* Volume of Cylinder = PI X Radius X Radius X Height */

System.out.format("Surface Area of Cylinder = %.3f\n", surfaceArea);
System.out.format("Volume of Cylinder = %.3f\n", volume);
}
}
```
Output
```Enter Base Radius of Cylinder
4
Enter Height of Cylinder
5
Surface Area of Cylinder = 226.195
Volume of Cylinder = 251.327
```

## Java program to find the volume and total surface area of cylinder using function

This java program is similar to above program except here we are using two user defined functions "getAreaOfCylinder" and "gerVolumeOfCylinder" functions to calculate total surface area and volume of cylinder respectively.

```package com.tcc.java.programs;

import java.util.Scanner;

/**
* Java Program to find volume and surface area of Cylinder using function
*/
public class VolumeOfCylinderFunction {

public static void main(String[] args) {
Scanner scanner;
scanner = new Scanner(System.in);
// Take input from user

System.out.println("Enter Height of Cylinder");
height = scanner.nextDouble();

System.out.format("Surface Area of Cylinder = %.3f\n", getAreaOfCylinder(radius, height));
System.out.format("Volume of Cylinder = %.3f\n", gerVolumeOfCylinder(radius, height));
}

public static double getAreaOfCylinder(double radius, double height) {
/*
* Total surface area of Cylinder = 2 X PI X Radius X (Radius + Height)
*/
}

public static double gerVolumeOfCylinder(double radius, double height) {
/* Volume of Cylinder = PI X Radius X Radius X Height */
}
}
```
Output
```Enter Base Radius of Cylinder
5
Enter Height of Cylinder
7
Surface Area of Cylinder = 376.991
Volume of Cylinder = 549.779
```

Recommended Posts
 Java Program to Find Volume and Surface Area of Cuboid Java Program to Calculate Surface Area and Volume of Cube Java Program to Calculate Volume and Surface Area of Cone Java Program to Find Area Of Trapezoid Java Program to Find Area Of Triangle Java Program to find Area Of Equilateral Triangle Java Program to Find Area of Right Angled Triangle Java Program to calculate area and circumference of circle Java Program to Calculate Volume of Sphere Java Program to Find Area and Perimeter of Rectangle Java Program to Find LCM and GCD of Two Numbers All Java Programs
 Previous Next