Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
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
<div class="execute"></div><div class="code-mirror language-java" contenteditable="plaintext-only" spellcheck="false" style="outline: none; overflow-wrap: break-word; overflow-y: auto; white-space: pre-wrap;"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Main</span> <span class="token punctuation">{</span>
<span class="token comment">//main method</span>
<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token comment">//declared a double variable 'radius'</span>
<span class="token comment">//and initialized with radius value</span>
<span class="token keyword">double</span> radius <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
<span class="token comment">//printing the given radius value of hemisphere</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"Given radius of hemisphere : "</span><span class="token operator">+</span>radius<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//calculate surface area by using formula</span>
<span class="token keyword">double</span> surfaceArea <span class="token operator">=</span> <span class="token number">2</span> <span class="token operator">*</span> <span class="token class-name">Math</span><span class="token punctuation">.</span>PI <span class="token operator">*</span> radius <span class="token operator">*</span> radius<span class="token punctuation">;</span>
<span class="token comment">//print the result</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"Surface area of hemisphere is : "</span> <span class="token operator">+</span> surfaceArea<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</div><div class="output-wrapper"><div class="console-close"></div><div class="code-output"></div></div>
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
<div class="execute"></div><div class="code-mirror language-java" contenteditable="plaintext-only" spellcheck="false" style="outline: none; overflow-wrap: break-word; overflow-y: auto; white-space: pre-wrap;"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Main</span> <span class="token punctuation">{</span>
<span class="token comment">//main method</span>
<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token comment">//declared a double variable 'radius'</span>
<span class="token comment">//and initialized with radius value</span>
<span class="token keyword">double</span> radius <span class="token operator">=</span> <span class="token number">6</span><span class="token punctuation">;</span>
<span class="token comment">//printing the given radius value of hemisphere</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"Given radius of hemisphere : "</span><span class="token operator">+</span>radius<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//calculate surface area by using formula</span>
<span class="token keyword">double</span> surfaceArea <span class="token operator">=</span> <span class="token number">2</span> <span class="token operator">*</span> <span class="token class-name">Math</span><span class="token punctuation">.</span>PI <span class="token operator">*</span> <span class="token class-name">Math</span><span class="token punctuation">.</span><span class="token function">pow</span><span class="token punctuation">(</span>radius<span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//print the result</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"Surface area of hemisphere is : "</span> <span class="token operator">+</span> surfaceArea<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</div><div class="output-wrapper"><div class="console-close"></div><div class="code-output"></div></div>
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
<div class="execute"></div><div class="code-mirror language-java" contenteditable="plaintext-only" spellcheck="false" style="outline: none; overflow-wrap: break-word; overflow-y: auto; white-space: pre-wrap;"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Main</span> <span class="token punctuation">{</span>
<span class="token comment">//main method</span>
<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token comment">//declared a double variable 'radius'</span>
<span class="token comment">//and initialized with radius value</span>
<span class="token keyword">double</span> radius <span class="token operator">=</span> <span class="token number">5.5</span><span class="token punctuation">;</span>
<span class="token comment">//printing the given radius value of hemisphere</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"Given radius of hemisphere : "</span><span class="token operator">+</span>radius<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//calling the method</span>
<span class="token function">findSurfaceArea</span><span class="token punctuation">(</span>radius<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment">//user defined method to find surface area of hemisphere</span>
<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">findSurfaceArea</span><span class="token punctuation">(</span><span class="token keyword">double</span> radius<span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token comment">//calculate surface area by using formula</span>
<span class="token keyword">double</span> surfaceArea <span class="token operator">=</span> <span class="token number">2</span> <span class="token operator">*</span> <span class="token class-name">Math</span><span class="token punctuation">.</span>PI <span class="token operator">*</span> <span class="token class-name">Math</span><span class="token punctuation">.</span><span class="token function">pow</span><span class="token punctuation">(</span>radius<span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//print the result</span>
<span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"Surface area of Hemisphere is : "</span> <span class="token operator">+</span> surfaceArea<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</div><div class="output-wrapper"><div class="console-close"></div><div class="code-output"></div></div>
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.
