Java program to find the area of a square


A square is a rectangle whose length and breadth are same. Therefore, Area of a rectangle is the square of its length. so, to calculate the area of a square

  • Get the length of the square form the user.
  • Calculate its square.
  • Print the square.

Example

import java.util.Scanner;
public class AreaOfSquare {
   public static void main(String args[]){
      int length, area;
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter the length of the square ::");
      length = sc.nextInt();
      area = length* length;
      System.out.println("Area of the square is ::"+area);
   }
}

Output

Enter the length of the square ::
55
Area of the square is ::3025

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 13-Mar-2020

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements