In the previous article, we have seen Java Program to Check Whether Given Four Points Form Pythagorean Quadruple
In this article we are going to see how to find the circumference of parallelogram using Java programming language.
Java Program to Find Circumference of a Parallelogram
Before Jumping into the program directly let’s see how we can find the circumference of parallelogram.
Explanation:
In Parallelogram, the opposite sides are of equal length and parallel to each other. Formula to find circumference of parallelogram = 2(l+b) or (2 * l) + (2 * b) Where, l and b represents the length of two adjacent sides.
Example:
Let one of the sides of parallelogram be “l” = 1 And the other side of parallelogram be “b” = 1 So, vol. of parallelogram = 2(l+b) = 2(1+1) = 2*2 = 4
Let’s see different ways to find circumference of parallelogram.
Method-1: Java Program to Find Circumference of a Parallelogram By Using Static Value
Approach:
- Declare two double variables say ‘l’ and ‘b’, assign the value to it, which holds the value for the 2 equal and opposite sides of parallelogram.
- Find the surface area of parallelogram using the formula
2(l+b)
- Print the result.
Program:
class Main { public static void main(String [] args) { double l = 1; double b = 1; //find circumferance double circumferance = 2*(l+b); System.out.println("The circumference of parallelogram is: "+ circumferance); } }
Output: The circumference of parallelogram is: 4.0
Method-2: Java Program to Find Circumference of a Parallelogram By Using Static Value
Approach:
- Declare two double variables say ‘l’ and ‘b’, take the value as user input.
- Find the surface area of parallelogram using the formula
2(l+b)
- Print the result.
Program:
import java.util.*; class Main { public static void main(String [] args) { Scanner s = new Scanner(System.in); System.out.println("Enter the value of one side of the parallelogram: "); double l = s.nextInt(); System.out.println("Enter the value of other side of the parallelogram: "); double b = s.nextInt(); //find circumferance double circumferance = 2*(l+b); System.out.println("The circumference of parallelogram is: "+ circumferance); } }
Output: Enter the value of one side of the parallelogram: 10 Enter the value of other side of the parallelogram: 8 The circumference of parallelogram is: 36.0
Method-3: Java Program to Find Circumference of a Parallelogram By Using Static Value
Approach:
- Declare two double variables say ‘l’ and ‘b’, take the value as user input.
- Call the user defined method
findCircumferance()
and passl
ndb
as parameter. - Inside method, find the surface area of parallelogram using the formula
2(l+b)
- Print the result.
Program:
import java.util.*; class Main { public static void main(String [] args) { //Scanner class object created Scanner s = new Scanner(System.in); //taking input of both sides value of parallelogram System.out.println("Enter the value of one side of the parallelogram: "); double l = s.nextInt(); System.out.println("Enter the value of other side of the parallelogram: "); double b = s.nextInt(); //calling the method findCircumferance() findCircumferance(l,b); } public static void findCircumferance(double l,double b) { //find circumferance double circumferance = 2*(l+b); System.out.println("The circumference of parallelogram is: "+ circumferance); } }
Output: Enter the value of one side of the parallelogram: 10 Enter the value of other side of the parallelogram: 8 The circumference of parallelogram is: 36.0
Our website provided core java programs examples with output aid beginners and expert coders to test their knowledge gap and learn accordingly.
Related Java Articles: