What is Pronic Number
A pronic number is a number which is represented by the product of two consecutive numbers , that is a number of the form "n x (n+1)". They are also called rectangular numbers, oblong numbers and heteromecic numbers.Examples :
Number to check : 12 3 x 4 = 12 // 12 is a pronic number
Number to check : 20
4 x 5 = 20 // 20 is a pronic number
Number to check : 30
5 x 6 = 30 // 30 is a pronic number
Number to check : 48
6 x 8 = 48 // 48 is not a pronic number
Pronic numbers upto 100 are : 0, 2, 6, 12, 20, 30, 42, 56, 72, 90 etc.
Read Also : Happy Number Program in Java
Algorithm to find Pronic Number
1. Check number N is pronic or not.2. Calculate the square root K of the given number N.
3. Multiply K * (K+1), if result is equal to the number N, then N is a pronic number otherwise not.
Java Program to find Pronic Number
import java.util.*; public class JavaHungry {
public static void main(String args[]) {
System.out.println("Enter input number "); Scanner sc = new Scanner(System.in); int inputNumber = sc.nextInt(); int sqrtNum = (int) Math.sqrt(inputNumber); int product = sqrtNum * (sqrtNum + 1); if (product == inputNumber) System.out.println("Pronic Number"); else System.out.println("Not a Pronic Number");
} }
Output :
Enter input number : 12
Pronic Number
Points to Remember :
1. According to Wikipedia, all pronic numbers are even. 2 is the only prime pronic number.2. If number 25 is appended to the decimal representation of any pronic number, the outcome will always be a square number.
Examples :
625 = 252 // 6 is a pronic number , 25 appended = 625 is a square number.
1225 = 352 // 12 is a pronic number , 25 appended = 1225 is a square number.
That's all for today, please mention in comments if you know any other way to check pronic number in java.