Site icon

Find area & perimeter of a square in java (with example)

What is Square shape ?

The square is a fundamental shape in geometry, characterized by several defining properties. It is a polygon with four equal sides and four right angles (90-degree angles) at each corner.

Key features of a square shape:

FIg 1: Square Shape

How to find area & perimeter of square?

What is area of square?

What is area of square?

Fig 2: Area & Perimeter of square

What are applications of Square shape?

Squares find extensive use in various fields such as mathematics, architecture, art, and engineering due to their symmetry and predictable properties. They serve as foundational shapes in many geometric concepts and constructions.

What is approach to find area & perimeter of square?

Program: calculate area & perimeter of a square in java

package org.learn;

import java.util.Scanner;

public class AreaAndPerimeterOfSquare {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			System.out.printf("1. Enter side of square : ");
			double side = scanner.nextDouble();			
				
			//Area of square is side * side
			double area = side * side;
			//Print area up to two precision
			System.out.printf("2. Area of square is : %4.2f",area);
			
			//Area of square is side * side
			double Perimeter = 4 * side;
			//Print area up to two precision
			System.out.printf("\n3. Perimeter of square is : %4.2f",Perimeter);
		}
	}
}

Output: area &  perimeter of a square in java

1. Enter side of square : 5
2. Area of square is : 25.00
3. Perimeter of square is : 20.00

1. Enter side of square : 7
2. Area of square is : 49.00
3. Perimeter of square is : 28.00
Exit mobile version