This is a Java Program to Find the Perimeter of a Circle, Rectangle and Triangle.

formula:

Perimeter of circle=2*pi*r

Perimeter of rectangle=2*(l+b)

Perimeter of triangle=(s1+s2+s3)

formula:

Perimeter of circle=2*pi*r

Perimeter of rectangle=2*(l+b)

Perimeter of triangle=(s1+s2+s3)

Enter the radius of the circle, length and breadth of the rectangle and three sides of the triangle as inputs. Calculate the perimeter by using formula and get the desired output.

Here is the source code of the Java Program to Find the Perimeter of a Circle, Rectangle and Triangle. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

import java.util.Scanner;

public class Perimeter

`{`

int r, l, b, s1, s2, s3;

double pi = 3.14,perimeter;

Scanner s = new Scanner(System.in);

void circle()

`{`

System.out.print("Enter radius of circle:");

r = s.nextInt();

perimeter = 2 * pi * r;

System.out.println("Perimeter of circle:"+perimeter);

`}`

void rectangle()

`{`

System.out.print("Enter length of rectangle:");

l = s.nextInt();

System.out.print("Enter breadth of rectangle:");

b = s.nextInt();

perimeter = 2 * (l + b);

System.out.println("Perimeter of rectangle:"+perimeter);

`}`

void triangle()

`{`

System.out.print("Enter length of first side of triangle:");

s1 = s.nextInt();

System.out.print("Enter length of second side of triangle:");

s2 = s.nextInt();

System.out.print("Enter length of third side of triangle:");

s3 = s.nextInt();

perimeter = s1 + s2 + s3;

System.out.println("Perimeter of triangle:"+perimeter);

`}`

public static void main(String[] args)

`{`

Perimeter obj = new Perimeter();

obj.circle();

obj.rectangle();

obj.triangle();

`}`

`}`

Output:

$ javac Perimeter.java $ java Perimeter Enter radius of circle:4 Perimeter of circle:25.12 Enter length of rectangle:5 Enter breadth of rectangle:6 Perimeter of rectangle:22.0 Enter length of first side of triangle:3 Enter length of second side of triangle:4 Enter length of third side of triangle:5 Perimeter of triangle:12.0

**Sanfoundry Global Education & Learning Series – 1000 Java Programs.**

advertisement

advertisement

Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.

**If you find any mistake above, kindly email to [email protected]**

**Related Posts:**

- Check Programming Books
- Practice Information Technology MCQs
- Practice BCA MCQs
- Apply for Computer Science Internship
- Check Java Books