Computer Science, asked by shree102, 1 year ago

Write a java program which displays perimeter of square and rectangle .​

Answers

Answered by jithilpeter
0

Answer:

Perimeter of square

/* Java Program Example - Calculate Area Perimeter of Square */

 

import java.util.Scanner;

public class JavaProgram

{

   public static void main(String args[])

   {

       int side, peri, area;

       Scanner scan = new Scanner(System.in);

 

       System.out.print("Enter Side Length of Square : ");

       side = scan.nextInt();

 

       area = side*side;

       peri = 4*side;

 

       System.out.print("Area = " +area);

 

       System.out.print("\nPerimeter = " +peri);

   }

}

Perimeter  of rectangle

/* Java Program Example - Calculate Area Perimeter of Rectangle */

 

import java.util.Scanner;

public class JavaProgram

{

   public static void main(String args[])

   {

       int len, bre, peri, area;

       Scanner scan = new Scanner(System.in);

 

       System.out.print("Enter Length and Breadth of Rectangle : ");

       len = scan.nextInt();

       bre = scan.nextInt();

 

       area = len*bre;

       peri = (2*len) + (2*bre);

 

       System.out.print("Area = " +area);

 

       System.out.print("\nPerimeter = " +peri);

   }

}

Explanation:

Similar questions