# Capricorn or Kaprekar Number Program in Java

A number is called Capricorn or Kaprekar number whose square is divided into two parts in any conditions and parts are added, the additions of parts is equal to the number, is called Capricorn or Kaprekar number.

Example: 45

```45 =  (45)2 = 2025

2025
All parts for 2025:-
202 + 5 = 207 (not 45)
20 + 25 = 45
2 + 025 = 27 (not 45)

Above we can see one combination is equal to number so that 45 is Capricorn or Kaprekar number.
```
import java.util.Scanner;

public class CapricornNumber
{

public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number=");
int n = scanner.nextInt();
boolean isCapricorn = false;

int square = n * n;
int temp = square;
int contDigits = 0;

while (temp > 0)
{
contDigits++;
temp /= 10;
}

for (int i = 1; i < contDigits; i++)
{
int divisor = (int) Math.pow(10, i);
int quotient = square / divisor;
int remainder = square % divisor;
if (quotient + remainder == n)
{
isCapricorn = true;
}
}
if (isCapricorn)
{
System.out.println("Capricorn/Kaprekar number");
} else
{
System.out.println("Not Capricorn/Kaprekar number");
}
}
}

```Output:Enter a number=297
Capricorn/Kaprekar number
What is Kaprekar Number?A number is called Capricorn or Kaprekar number whose square is divided into two parts in any conditions and parts are added, the additions of parts is equal to the number, is called Capricorn or Kaprekar number. Example:45 =  (45)2 = 2025 =20 + 25 = 45
1 = 12 = 01 = 0 + 1 = 1 java java programs number based program      {
"@context":"http://schema.org",
"@type": "TechArticle",
"url": "https://www.efaculty.in/java-programs/capricorn-or-kaprekar-number-program-in-java/",
"headline": "Capricorn or Kaprekar Number Program in Java",
"alternativeHeadline": "Capricorn or Kaprekar Number Program in Java",
"dateCreated": "October 16, 2021",
"datePublished": "October 16, 2021",
"dateModified": "March 30, 2022",
"inLanguage": "en-US",
"isFamilyFriendly": "true",
"contentLocation": {
"@type": "Place",
"name": "Varanasi, Uttar Pradesh, India - 221002"
},
"author": {
"@type": "Person",
"name": "Afaq Ahmad Khan",
"url": "https://www.efaculty.in"
},
"publisher": {
"@type": "Organization",
"name": "Afaq Ahmad Khan",
"url": "https://www.efaculty.in",
"logo": {
"@type": "ImageObject",
"url": "https://www.efaculty.in/wp-content/themes/efacluty/images/logo.png",
"width":"350",
"height":"65"
}
},
"mainEntityOfPage": "True",
"keywords": ["java","java programs","number based program"],
"genre":["SEO","JSON-LD"],
"articleSection": "Java",
"articleBody": "A number is called Capricorn or Kaprekar number whose square is divided into two parts in any conditions and parts are added, the additions of parts is equal to the number, is called Capricorn or Kaprekar number.

Example: 45
<pre>45 =  (45)<sup>2</sup> = 2025

2025
All parts for 2025:-
202 + 5 = 207 (not 45)
20 + 25 = 45
2 + 025 = 27 (not 45)

Above we can see one combination is equal to number so that 45 is Capricorn or Kaprekar number."
} ```
Recent Posts