Pronic Number in Java

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.

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

  1. Calculate the square root of number and taking floor of the number by typecasting it to
  2. 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.

Leave a Comment

Your email address will not be published. Required fields are marked *