Finding perimeter of parallelogram: In the previous article we have discussed Java Program to Find Area of Equilateral Triangle
In this article we will discuss about how to find perimeter of parallelogram.
Program to Find Perimeter of Parallelogram
How to find perimeter of parallelogram: Before jumping into the program directly, let’s first see how we calculate perimeter of parallelogram.
Formula for Perimeter of Parallelogram : 2*(length+breadth)
Where,
- ‘length‘ represents length of parallelogram.
- ‘
breadth
‘ represents height of parallelogram.
Let’s see different ways to do it.
If you are new to Java and want to learn the java coding skills too fast. Try practicing the core java programs with the help of the Java basic programs list available.
Method-1: Java Program to Find Perimeter of Parallelogram By Using Static Value
Finding perimeter of parallelogram: In this method, the value for length and breadth are already declared in the program. Then these value will be used to calculate the perimeter of parallelogram using the formula and then the result will be displayed.
Let’s see the program to understand it more clearly.
import java.util.*; public class Main { public static void main(String args[]) { //Object of Scanner class is created Scanner sc= new Scanner(System.in); //breadth declared double breadth= 2.9; //length declared double length= 5.9; //Finding the perimeter using the formula double perimeter=2*(length+breadth); System.out.println("Perimeter of Parallelogram : " + perimeter); } }
Output: Perimeter of Parallelogram : 17.6
Method-2: Java Program to Find Perimeter of Parallelogram By User Input Value
In this method, we have taken the length and breadth input of parallelogram as user input means it will ask the user to input the value for length and breadth. Then these value will be used to calculate the perimeter of parallelogram using the formula and then the result will be displayed.
Let’s see the program to understand it more clearly.
import java.util.*; public class Main { public static void main(String args[]) { //Object of Scanner class is created Scanner sc= new Scanner(System.in); //Taking breadth as user input System.out.println("Enter breadth of the Parallelogram : "); double breadth= sc.nextDouble(); //Taking length as user input System.out.println("Enter length of the Parallelogram : "); double length= sc.nextDouble(); //Finding the perimeter using the formula double perimeter=2*(length+breadth); System.out.println("Perimeter of Parallelogram : " + perimeter); } }
Output: Enter breadth of the Parallelogram : 4.5 Enter length of the Parallelogram : 5.6 perimeter of Parallelogram : 20.2
Method-3: Java Program to Find Perimeter of Parallelogram By User Defined Method
In this method, we have implemented the same Perimeter finding logic with in a user defined method say findPerimeter()
and passed the length and breadth of parallelogram as parameter. This findPerimeter()
method will find the perimeter and will display the result.
Let’s see the program to understand it more clearly.
import java.util.*; public class Main { public static void main(String args[]) { //Object of Scanner class is created Scanner sc= new Scanner(System.in); //Taking breadth as user input System.out.println("Enter breadth of the Parallelogram:"); double breadth= sc.nextDouble(); //Taking length as user input System.out.println("Enter length of the Parallelogram:"); double length= sc.nextDouble(); findPerimeter(length,breadth); } public static void findPerimeter(double length,double breadth) { //Finding the perimeter using the formula double perimeter=2*(length+breadth); System.out.println("Perimeter of Parallelogram : " + perimeter); } }
Output: Enter breadth of the Parallelogram : 4.5 Enter length of the Parallelogram : 5.6 perimeter of Parallelogram : 20.2
Grab the opportunity to learn all effective java programming language concepts from basic to advance levels by practicing these Java Program Examples with Output
Related Java Programs: