- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to Find Area of Square
In this article, we will understand how to find the area of a square. The area of a square is calculated using the following formula −
side*side i.e. s2
Below is a demonstration of the same −
If the side of a square is s, the area of the square is given by s2 −
Input
Suppose our input is −
Length of the side : 4
Output
The desired output would be −
Area of the square : 16
Algorithm
Step 1 - START Step 2 - Declare 2 integer values namely my_side and my_area. Step 3 - Read the required values from the user/ define the values. Step 4 – Calculate the area of the square using the formula side*side and store the result Step 5- Display the result Step 6- Stop
Example 1
Here, the input is being entered by the user based on a prompt. You can try this example live in ourcoding ground tool .
import java.util.Scanner; public class AreaOfSquare { public static void main(String args[]){ int my_side, my_area; System.out.println("Required packages have been imported"); Scanner my_scanner = new Scanner(System.in); System.out.println("A reader object has been defined "); System.out.print("Enter the length of a side : "); my_side = my_scanner.nextInt(); my_area = my_side* my_side; System.out.println("The my_area of the square is :"+my_area); } }
Output
Required packages have been imported A reader object has been defined Enter the length of a side : 4 The area of the square is :16
Example 2
Here, the integer has been previously defined, and its value is accessed and displayed on the console.
public class AreaOfSquare { public static void main(String args[]){ int my_side, my_area; my_side = 4; System.out.println("The length of the side of the square is defined as : " +my_side); my_area = my_side* my_side; System.out.println("The my_area of the square is :"+my_area); } }
Output
The length of the side of the square is defined as : 4 The area of the square is :16
- Related Articles
- Java program to find the area of a square
- Swift Program to Find Area of Square
- Kotlin Program to Find Area of Square
- Java program to find the area of a rectangle
- Java program to find the area of a triangle
- Java program to find the area of a circle
- Java Program to Find the Area of a Parallelogram
- Java Program to Find the Area of a Trapezium
- How to Find Area of Square in Golang?
- Program for Area Of Square in C++
- Program to find area of largest square of 1s in a given matrix in python
- Java program to find the square root of a given number
- Swift Program to Calculate Area of Circle Inscribed in Square
- Java Program to Find the Surface area and Volume of Cuboid
- Find the Area of a Circle in Java Program

Advertisements