pronic number in java

Let’s learn pronic number in java.

pronic number in java

pronic number is a number which is product of two consecutive integers.

For example:

56 = 7 * 8

Here consecutive integers are 7 and 8.

Another example:

72 = 8 * 9

Here consecutive integers are 8 and 9.

Here are few pronic numbers 0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462.

Now let’s see pronic number program.

import java.util.Scanner;
public class PronicNumberJava
{
   public static void main(String[] args)
   {
      Scanner sc = new Scanner(System.in);
      System.out.print("Please input a number: ");
      int number = sc.nextInt();
      int pronic = 0;
      for(int p = 0; p < number; p++)
      {
         if(p * (p + 1) == number)
         {
            pronic = 1;
            break;
         }
      }
      if(pronic == 1)
      {
         System.out.println(number + " is a pronic number.");
      }
      else
      {
         System.out.println(number + " is not a pronic number.");
      }
      sc.close();
   }
}


Output:

Please input a number: 342
342 is a pronic number.

Please input a number: 240
240 is a pronic number.

Please input a number: 400
400 is not a pronic number.


Also read – java overview