Problem: Write a Java program to check whether the given number is a Pronic number or not.

A pronic number is a number that can be represented as a product of two consecutive numbers.

Some examples of pronic numbers are: 6, 12, 20, etc.

Pronic numbers

A pronic number is also known as a Rectangular or Oblong number.

To check whether a number is pronic in java, we find the square root of the number or the number close to the square root (because the product of any two consecutive numbers is always closest to the square of one of them).

Then we check if its product with the next number (n+1) is equal to the original number. If so, the number is pronic otherwise not.

Output:

Enter a number
12
Pronic number

Print all Pronic Numbers in Given Interval

To print all pronic numbers in the given interval, we write the logic of checking the protonic number in a separate function and call the same for each number in the given interval.

Output:

Enter a lower and upper range value: 1 100
2 6 12 20 30 42 56 72 90

In this programming example, we learned to check pronic number using the Java language.

Leave a Reply

2 × five =