public class SquareArea {
public static void main(String[] args) {
double side = 5;
double area = side * side;
System.out.println("Area of square is " + area);
}
}
Area of square is 25.0
double
variable side
and initialize it with the value 5, which represents the length of one side of the square
. 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.