Java Program to Find Area of the Larger Circle when Radius of the Smaller Circle and Difference in the Area is Given

In the previous article, we have discussed about Java Program to Find Minimum Revolutions to Move Center of a circle to a Target

In this article we are going to see how to find area of the larger circle when radius of the smaller circle and difference in the area is given by using Java programming language.

Java Program to Find Area of the Larger Circle when Radius of the Smaller Circle and Difference in the Area is Given

Before Jumping into the program directly let’s see how to find area of the larger circle when radius of the smaller circle and difference in the area is given.

There are 2 circles, where one is a larger circle and the other is a smaller circle. Given the radius of the larger circle is “R” and radius of smaller circle is “r” .The difference of area’s between the circle is “diff

Now, area of the larger circle can be found by:
Diff = (Area of larger circle) - (Area of smaller circle)

Diff = (Pi*R2) – (Pi*r2)

R2= (diff/pi) + r2

So, area of larger circle = pi*R2

where R = radius of larger circle

Pi = 3.142

Example:

r = 5

diff = 10

R2= (diff/pi) + r2  = 79.5671

Ar = pi*R2 = 250

Let’s see different ways to find area of the larger circle when radius of the smaller circle and difference in the area is given.

Method-1: Java Program to Find Area of the Larger Circle when Radius of the Smaller Circle and Difference in the Area is Given By Using Static Input Value

Approach:

  • Declare an double variable say ‘r’ and assign the value to it, which holds the smaller radius value of the circle.
  • Declare an double variable say ‘diff’ and assign the value to it, which holds the difference between the areas of two circles.
  • Find the of radius (say ”R”) of larger circle using the formula (diff/pi) + r2
  • Find the area of the larger circle using the formula pi*R2
  • Print the result.

Program:

import java.io.*;
class Main
{
    public static void main(String [] args)
    {
        double r = 5;
        double diff = 10;
        // formula to find sq. of radius of larger circle
        double R =  (diff/3.142) + (r*r);   
        // formula to find Ar of larger circle
         double Ar =  3.142 * R;     
        System.out.println("the area of the larger circle is "+ Ar);
    }
}
Output:

the area of the larger circle is 88.55

Method-2: Java Program to Find Area of the Larger Circle when Radius of the Smaller Circle and Difference in the Area is Given By Using User Input Value

Approach:

  • Declare an double variable say ‘r’ and take the value as user input, which holds the smaller radius value of the circle.
  • Declare an double variable say ‘diff’ and take the value as user input, which holds the difference between the areas of two circles.
  • Then we will take the value of “r”, “diff” as user input using scanner class.
  • Find the of radius (say ”R”) of larger circle using the formula (diff/pi) + r2
  • Find the area of the larger circle using the formula pi*R2
  • Print the result.

Program:

import java.io.*;
import java.util.Scanner;
class Main
{
    public static void main(String [] args)
    {
       // scanner class obj ref 
        Scanner s = new Scanner(System.in);                         
        System.out.println("Enter the radius of smaller circle");
        // to take user input value
        double r = s.nextDouble();                                          
        System.out.println("Enter the difference in areas of the two circles");
        double diff =  s.nextDouble();     
        // formula to find sq. of radius of larger circle
        double R =  (diff/3.142) + (r*r);   
        // formula to find Ar of larger circle
        double Ar =  3.142 * R;     
        System.out.println("The area of the larger circle is " + Ar);        
    }
}
Output:

Enter the radius of smaller circle
7.5
Enter the difference in areas of the two circles
42.6
The area of the larger circle is 219.33749999999998

Explore complete java concepts from the Java programming examples and get ready to become a good programmer and crack the java software developer interview with ease.

Related Java Programs: