- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes

- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages

- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation

- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples

# Find the Area of a Circle Inscribed in a Square in Java

A circle is a round shape two-dimensional diagram which has no corners. Every circle has an origin point and every point on the circle maintains equal distance from the origin. The distance between the origin and a point in a circle is known as Radius of the circle. And similarly, if we draw a line from one edge to another edge of the circle and the origin is held in the middle of it, that line is known as diameter of the circle. Basically, the diameter is double of the length of the radius.

A square consists of four sides and all the four sides have equal length. If we try to put a circle inside a square with maximum radius possible, then the diameter of the circle is equal to the length of the side of the square. So here we can conclude that the radius of the circle is equal to half of the square’s side length.

Area of the circle refers to the total surface area acquired by the circle. We can calculate the square of the circle by using radius and a constant known as π

Formula to calculate area of the circle −

$$\mathrm{Area=\pi \times (radius)^{2}}$$

As the circle is inscribed in a square then radius of circle (r) = side/2 Where, ‘side’ refers to the side length of the square.

$$\mathrm{Area \;of \; inscribed \;circle \;in \;square=\varpi\times(side/2)^{2}=\varpi\times(side^{2}/4)=(\varpi/4)^{*}sides^{2}}$$

In this article we will see how we can find the area of the circle inscribed in a square using Java.

## To show you some instances −

Instance-1

The side length of the square given = 9 The area of the circle inscribed in square = (ϖ / 4) * side2 = (3.141/4) * 9 * 9 = 63.605

## Instance-2

The side length of the square given = 50 The area of the circle inscribed in square = (ϖ / 4) * side2 = (3.141/4) * 50 * 50 = 1963.125

## Instance-3

The side length of the square given = 32 The area of the circle inscribed in square = (ϖ / 4) * side2 = (3.141/4) * 32 * 32 = 804.096

## Algorithm

**Step-1** − Get the side length of the square either by static input or by user input.

**Step-2** − Find the area of the circle inscribed in a square by using the formula.

**Step-3** − Print the result.

**Multiple Approaches**

We have provided the solution in different approaches.

By Using Static Input Value.

By Using User-Defined Method with Static Input Value.

By Using User-Defined Method with User Input Value.

Let’s see the program along with its output one by one.

## Approach-1: By Using Static Input Value

In this approach, we declare a double variable and initialize it with the side length of the square. Then by using the algorithm we can find the area of the circle inscribed in a square.

## Example

import java.io.*; public class Main { //main method public static void main (String[] args) { //declare a variable to store the value of pi double pi = 3.14; //declare a variable to store the value of side of the square float side = 15; //declare a variable to store the area of the circle //find area by using the formula double area = ( pi / 4 ) * side * side; System.out.println("Area of the circle inscribed in the square is: "+ area); } }

## Output

Area of the circle inscribed in the square is: 176.625

## Approach-2: By Using User Defined Method with Static Input Value

In this approach, we declare a double variable and initialize the side length value of the square. Then by using the algorithm we can find the area of the circle inscribed in a square.

## Example

import java.io.*; public class Main { //declare a static variable to store the value of pi static double pi = 3.14; //main method public static void main (String[] args) { //declare a variable to store the value of side of the square float side = 15; System.out.println("Area of the circle inscribed in the square is: "+ areaOfCircle(side)); } // user-defined method to find the area of the circle static double areaOfCircle(float side) { return ( pi / 4 ) * side * side; } }

## Output

Area of the circle inscribed in the square is: 176.625

## Approach-3: By Using User Defined Method with User Input Value

In this approach, we declare a double variable and take the user input of the side length of the square. Then by using the algorithm we can find the area of the circle inscribed in a square.

## Example

import java.io.*; import java.util.*; public class Main { //declare a static variable to store the value of pi static double pi = 3.14; //main method public static void main (String[] args) { //Create object of Scanner class Scanner sc= new Scanner(System.in); System.out.print("Enter the length of side of the square: "); //declare a variable to store the value of side of the square double side = sc.nextDouble(); System.out.println("Area of the circle inscribed in the square is: "+ areaOfCircle(side)); } // user-defined method to find the area of the circle static double areaOfCircle(double side) { return ( pi / 4 ) * side * side; } }

## Output

Enter the length of side of the square: 9 Area of the circle inscribed in the square is: 63.585

**In this article, we explored how to find the area of a circle inscribed in a square in Java by using different approaches.**

- Related Articles
- Area of a square inscribed in a circle which is inscribed in a hexagon in C Program?
- Program to calculate the area of an Circle inscribed in a Square
- C Program for Area of a square inscribed in a circle which is inscribed in a hexagon?
- Area of a square inscribed in a circle which is inscribed in an equilateral triangle in C Program?
- Area of a square inscribed in a circle which is inscribed in an equilateral triangle in C Program?
- Find the area of the circle that can be inscribed in a square of side $6\ cm$.
- Find the area of the square that can be inscribed in a circle of radius $8\ cm$.
- A square of diagonal 8 cm is inscribed in a circle. Find the area of the region lying inside the circle and outside the square.
- Swift Program to Calculate Area of Circle Inscribed in Square
- If a square is inscribed in a circle, find the ratio of the areas of the circle and the square.
- Find the area of the circle in which a square of area \( 64 \mathrm{~cm}^{2} \) is inscribed. [Use \( \pi=3.14 \) ]
- Area of a circle inscribed in a rectangle which is inscribed in a semicircle?
- Area of a circle inscribed in a regular hexagon?
- Area of a circle inscribed in a rectangle which is inscribed in a semicircle in C?
- Find the area of largest circle inscribed in ellipse in C++