Java Program for Area of Square
Before calculating area and perimeter of square, let’s focus on some formulas we will use in coming examples.
Formula for area of a square is given below:
area = side * side
Formula for perimeter of a square is given below:
perimeter = 4 * side
Let’s calculate the area of square in java with different-different examples.
1) Area of Square in Java Example 1
This is simple java program to calculate are of square where side are given.
public static void main(String args)
double side = 6.5;//given side
double area = side * side;//using formula for area of a square
System.out.println(“Area of Square is : “+area);
Output: Area of Square is : 42.25
Now moving to next example where we use Scanner class for reading the data or input from the keyboard by the user.
2) Area of Square in Java Example 2
You can check for practice other java programs e.g How to calculate area and perimeter of rectangle and how to find area and circumference of cirlcle, etc.
3) Find the Perimeter of a Square in Java Example 3
Output: Enter side of Square
Area of Square is : 42.25
Perimeter of Square is : 26.0
In this article we have learned how to find the area of a square and how to find the perimeter of a square in java programming with simple examples.