Google News
logo
Java Program to Calculate area of Square
In the following examples of Java program to calculate the area of a square :
Program :
public class SquareArea {

    public static void main(String[] args) {
        double side = 5;
        double area = side * side;
        System.out.println("Area of square is " + area);
    }
}
Output :
Area of square is 25.0
In this program, we first declare a double variable side and initialize it with the value 5, which represents the length of one side of the square.

We then calculate the area of the square by multiplying the side by itself, and store the result in a double variable area. Finally, we print the area of the square using a formatted string.