java

Write a Java Program to Calculate the Area of Square

In this tutorial, we are going to see how to write a Java program to calculate the area of a square. In geometry, a square is a quadrilateral, which means it has four equal sides and four equal angles (90-degree angles). It can also be defined as a rectangle in which two adjacent sides have same lengths.

The area of a square is given by the formula area = side x side.
 

Example :

 


 
 

Java Program to Calculate the Area of Square:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		System.out.print("Enter the side of the square: ");
		Scanner sc = new Scanner(System.in);
		double side = sc.nextDouble();
		
		double area = side * side;
		
		System.out.println("The area of the square is " + area);
	}
}

Output:

Enter the side of the square: 4
The area of the square is 16.0
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *