Hi friends! In this tutorial, we’ll be learning how to write a Java program to calculate total surface area and curved surface area of cylinder. If you remember from our previous tutorial, we learned how to write a Java Program to calculate Surface Area and Volume of Sphere. If you haven’t checked it out yet, I recommend taking a look at it.

Before moving ahead and writing our program, first, we need to know the mathematical formula and concept behind it to calculate the total surface area and curved surface area of the cylinder.

## Curved Surface Area of Cylinder

The curved surface area (CSA), also known as the lateral surface area (LSA), of a cylinder is determined by measuring the curved surface of the cylinder with a base radius ‘r’ and height ‘h’. The mathematical formula for calculating the curved surface area or lateral area is as follows:

Curved Surface Area of Cylinder = 2πrh Square units

where,

**π**is a constant whose value is 22/7 or 3.1415**r**is the base radius of the cylinder**h**is the height of the cylinder

## Total Surface Area of Cylinder

The total surface area of a cylinder can be calculated by adding up the areas of all its faces. For a cylinder with a radius ‘r’ and height ‘h’, the total surface area is the sum of the curved surface area and the areas of the circular bases of the cylinder.

Total Surface Area of Cylinder = Curved Surface Area + Areas of circular basesTotal Surface Area of Cylinder = 2πrh + 2πr^{2 }

Total Surface Area of Cylinder = 2πr(h + r) Square units

where,

**π**is a constant whose value is 22/7 or 3.1415**r**is the base radius of the cylinder**h**is the height of the cylinder

Now let’s learn how to calculate them in Java programming.

## Java Program to Calculate Total Surface Area and Curved Surface Area of Cylinder

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
package java_programs_example; import java.util.*; public class Cylinder { public static void main(String[] args){ double radius, height,csa,tsa; Scanner in=new Scanner(System.in); System.out.println("Enter the base radius of the Cylinder"); radius=in.nextDouble(); System.out.println("Enter the height of the Cylinder"); height=in.nextDouble(); csa= 2*Math.PI*radius*height;//calculating curved surface area of the cylinder tsa=2*Math.PI*radius*(height+radius);//calculating total surface area of the cylinder System.out.println("Curved Surface area of the Cylinder = "+csa+" Square units"); System.out.println("Total Surface area of the Cylinder = "+tsa+" Square units"); } } |

### What we did?

We have written Java program to calculate total surface area and curved surface area of cylinder successfully. Now we will explain what we did in our program.

- First of all we imported the util package.
- Then we have created a public class named as Cylinder.
- Inside Cylinder class we created main() method.
- Then we have declared variables which are used in this program.
- Now we created object of the Scanner class.
- Then asked the user to enter the radius and height of the cylinder.
- In next line read the value of radius and height entered by the user.
- Then calculated curved suface area of the cylinder using formula
**2*Math.PI * radius*height**. Instead of using**Math.PI**we can also write the value of pi (3.14 or 22/7) directly. - In next line calculated total surface area of the cylinder using formula
**2 * Math.PI * radius*(height+radius).** - Then at last printed curved surface area and total surface area of the cylinder on screen.

**Output**

1 2 3 4 5 6 |
Enter the base radius of the Cylinder 5 Enter the height of the Cylinder 10 Curved Surface area of the Cylinder = 314.1592653589793 Square units Total Surface area of the Cylinder = 471.23889803846896 Square units |

Now this tutorial on **Java Program to calculate total surface Area and curved surface area of cylinder **is completed. In the upcoming tutorials, we will delve into a series of Java programs dedicated to solving numerical problems.

**Related Tutorials…**

- Java Program to Calculate Area and Circumference of Circle
- Java Program to calculate Area of Triangle
- Java Program to calculate Area of Triangle using heron’s formula
- Java Program to calculate Area and Perimeter of Right Triangle
- Java Program to calculate Area and Perimeter of Rectangle
- Java Program to calculate Area and Perimeter of Square
- Java Prorgram to calculate Area and Perimeter of Parallelogram
- Java Program to calculate Area of Trapezium
- Java Program to calculate Area and Volume of Cube
- Java Program to calculate Area and Volume of Cuboid
- Java Program to calculate Volume of Cone
- Java Program to calculate Surface Area and Volume of Sphere