Pronic numbers are those numbers who can be written as a product of two consecutive integers.

It means, they are of the form: **P =** **n * (n + 1)**

For example, the number **56** can be written as **7 * 8**, that is, a product of two consecutive integers.

Hence, the number **56** is a Pronic number.

Pronic numbers are also called oblong numbers, heteromecic numbers, or rectangular numbers.

Some of the Pronic numbers are: 0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110 …

Below is a program that inputs a number, and checks whether it is a Pronic number or not.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import java.lang.Math; public class PronicNumber { static void checkForPronic(int number) { int squareRoot = (int)Math.sqrt(number); int product = squareRoot * (squareRoot + 1); if(product == number) System.out.println("The number is a Pronic number"); else System.out.println("The number is not a Pronic number"); } public static void main (String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a Number: "); int number = input.nextInt(); checkForPronic(number); } } |

The program runs on the following algorithm to check whether a number is Pronic or not.

- Calculate the square root of number and taking floor of the number by typecasting it to
- Find the product of the squareRoot and (squareRoot + 1), and then compare the product with the number.

We used the java.lang.Math function sqrt(), to calculate the square root.

Comment down below if you have queries related to pronic number in java.