Here, you will learn how to calculate the Area of a Square using the Formula (Side* Side). The Program takes the user input for Side, calculates the result, and displays the result on the screen.
If you do not know about the operators in java, click the link below to learn about operators as this program is using one.
Java Program to Calculate the Area of a Square
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | //Area of a square import java.util.Scanner; public class AreaofSquare { public static void main (String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter Side of Square: "); float side = scanner.nextInt(); //Area = side*side float area = side*side; System.out.println("Area of Square is: "+area); } } |
Output:
Enter Side of Square: 4
Area of Square is: 16.0