# Java Program to Find Minimum Revolutions to Move Center of a Circle to a Target

In the previous article, we have seenĀ Java Program to Solve Pizza Cut Problem(Circle Division by Lines)

In this article we will discuss about how to find minimum revolutions to move center of a circle to a target using java programming language.

## Java Program to Find Minimum Revolutions to Move Center of a Circle to a Target

Before jumping into the program directly, let’s first know how can we find minimum revolutions to move center of a circle to a target .

Explanation:

Formula to Find Minimum Revolutions to Move Center of a Circle to a Target: ceil(d/2*r)

Example:

When r=2,P1=(0,0), and P2=(0,4), d = 4

Minimum Revolutions: ceil(d/2*r)

=> ceil(4/2*2)

=>ceil(1)

=> 1

Let’s see different ways to find minimum revolutions to move center of a circle to a target.

### Method-1: Java Program to Find Minimum Revolutions to Move Center of a Circle to a Target By Using Static Value

Approach:

• Declare the value for the coordinates of the point, of radius and size of radius.
• Find the distance between both the points.
• Find the minimum revolutions using the formula ceil(distance/(2*radius))
• Then print the result.

Program:

import java.awt.Point;
import java.util.Scanner;
import static java.lang.Math.*;

public class Main
{
public static void main(String[] args){
// Static initialization of both points and the radius
Point p = new Point(0,4);
// Caclculates the distance between the radius and the point
// Prints the minimum revloutions
System.out.println("The minimum revolutions required is "+(int)Math.ceil(distance/(2*radius)));
}
}

Output:

The minimum revolutions required is 1

### Method-2: Java Program to Find Minimum Revolutions to Move Center of a Circle to a Target By User Input Value

Approach:

• Take user input the value for the coordinates of the point and radius and size of radius.
• Find the distance between both the points.
• Find the minimum revolutions using the formula ceil(distance/(2*radius))
• Then print the result.

Program:

import java.awt.Point;
import java.util.Scanner;
import static java.lang.Math.*;

public class Main
{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.println("Enter coordinates of the point");
Point p = new Point(scan.nextInt(),scan.nextInt());
// Caclculates the distance between the radius and the point
// Prints the minimum revloutions
System.out.println("The minimum revolutions required is "+(int)Math.ceil(distance/(2*radius)));
}
}

Output:

Enter coordinates of the point
5 5
The minimum revolutions required is 1