How To Find the Surface Area of Hemisphere in Java?


A hemisphere refers to the exact half of a sphere. Means if we divide a sphere in two equal parts then we will get two hemispheres. Hemisphere is a three-dimensional geometrical shape which has one flat face.

There are many practical examples of hemispheres. The earth divided into 2 equal parts results 2 hemispheres i.e. Northern hemisphere and Southern hemisphere.

The area occupied by the outer surface of a three-dimensional object is called the surface area.

Formula to calculate surface area of hemisphere −

Mathematically it can be represented as

$$\mathrm{Surface \:Area \:= \:2\pi\:r^2}$$

Mathematically it can be represented as

Volume = 2 * pi * r * r

Where, ‘r’ refers to the radius of the hemisphere

In this article we will see how we can find the surface area of the hemisphere by using Java programming language.

To show you some instances

Instance-1

Suppose radius(r) of hemisphere is 4.5.

Then by using surface area formula of hemisphere.

surface area = 127.234

Hence, the surface area of hemisphere is 127.234

Instance-2

Suppose radius(r) of hemisphere is 3.5

Then by using surface area formula of hemisphere

surface area = 76.96

Hence, the surface area of hemisphere is 76.96

Instance-3

Suppose radius(r) of hemisphere is 5

Then by using surface area formula of hemisphere

surface area = 157.07

Hence, the surface area of hemisphere is 157.07

Syntax

In Java we have a predefined constant in Math class of java.lang package i.e. Math.PI which gives us the pie value which is approximately equal to 3.14159265359.

Following is the syntax for that

Math.PI

To get the power of any number raised to the power of another number in Java we have inbuilt java.lang.Math.pow() method.

Following is the syntax to get power of 2 by using the method −

double power = math.pow (inputValue,2)

Algorithm

  • Step 1 − Get the radius of the hemisphere either by initialization or by user input.

  • Step 2 − Find the surface area of the hemisphere by using the surface area formula.

  • Step 3 − Print the result.

Multiple Approaches

We have provided the solution in different approaches.

  • By Using Static Input

  • By Using User Input

  • By Using User Defined Method

Let’s see the program along with its output one by one.

Approach-1: By Using Static Input

In this approach, the radius value of the hemisphere will be initialized in the program. Then by using the algorithm we will find the surface area.

Example

public class Main { //main method public static void main(String[] args) { //declared a double variable 'radius' //and initialized with radius value double radius = 10; //printing the given radius value of hemisphere System.out.println("Given radius of hemisphere : "+radius); //calculate surface area by using formula double surfaceArea = 2 * Math.PI * radius * radius; //print the result System.out.println("Surface area of hemisphere is : " + surfaceArea); } }

Output

Given radius of hemisphere : 10.0
Surface area of hemisphere is : 628.3185307179587

Approach-2: By Using User Input Value

In this approach, the user will be asked to take the input of the radius value of the cone. Then by using the surface area formula of the cone, find the surface area. Here we will make use of the Java inbuilt pow() method.

Example

public class Main { //main method public static void main(String[] args) { //declared a double variable 'radius' //and initialized with radius value double radius = 6; //printing the given radius value of hemisphere System.out.println("Given radius of hemisphere : "+radius); //calculate surface area by using formula double surfaceArea = 2 * Math.PI * Math.pow(radius,2); //print the result System.out.println("Surface area of hemisphere is : " + surfaceArea); } }

Output

Given radius of hemisphere : 6.0
Surface area of hemisphere is : 226.1946710584651

Approach-3: By Using User Defined Method

In this approach, the radius value of the hemisphere will be initialized in the program. Then we call a user defined method to find the volume by passing the radius value of the hemisphere as a parameter. Then inside the method by using the surface area formula, find the surface area of the hemisphere.

Example

public class Main { //main method public static void main(String[] args) { //declared a double variable 'radius' //and initialized with radius value double radius = 5.5; //printing the given radius value of hemisphere System.out.println("Given radius of hemisphere : "+radius); //calling the method findSurfaceArea(radius); } //user defined method to find surface area of hemisphere public static void findSurfaceArea(double radius) { //calculate surface area by using formula double surfaceArea = 2 * Math.PI * Math.pow(radius,2); //print the result System.out.println("Surface area of Hemisphere is : " + surfaceArea); } }

Output

Given radius of hemisphere : 5.5
Surface area of Hemisphere is : 190.0663555421825

In this article, we explored how to find the surface area of a hemisphere in Java by using different approaches.

Updated on: 17-Nov-2022

193 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements