Write a Java program to calculate the area of a square.

Q.6 Write a Java program to calculate the area of a square.

Solution  :- 

import java.util.Scanner;

public class AverageCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print(“Enter the side length of the square: “);
double side = scanner.nextDouble();
double area = side * side;
System.out.println(“The area of the square with side length ” + side + ” is: ” + area);

}
}

Output :- 

Leave a Reply

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

sign up!

We’ll send you the hottest deals straight to your inbox so you’re always in on the best-kept software secrets.