Java Program to check Pronic Number or Heteromecic Number Program


Introduction


This tutorial will help you to understand Pronic Number or Heteromecic Number Program. In-order to start writing any program we have to understand business requirement and what is the problem. As we know that Pronic Number or Heteromecic Number Program is a number which is the product of two consecutive integers, that is, a number of the form n(n + 1).

So we can say Tn = n*(n+1) where n is the number of term.

The first few pronic numbers are:
2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462 … etc.

Explanation:

First Term: 2 =1*2 = 2

Second Term: 6 = 2*3= 6

.

.

.


Flowchart


Please find sample flowchart diagram for this program as given below –

 

 


Program(Code) Using Java Language


package com.kw.sample;

import java.util.Scanner;

/**
 * This class helps to check Pronic Number.
 *
 * @author dsahu1
 *
 */
public class KWPronicNumberExample {

    public static void main(String args[]) {
        // This helps to take number from keyboard
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter a number : ");
        int n = sc.nextInt();
        Boolean flag = false;
        // Check number against each term in the series
        for (int i = 0; i < n; i++) {
            if (i * (i + 1) == n) {
                flag = true;
                break;
            }
        }

        if (flag) {

            System.out.println(n + " is a Pronic Number.");
        } else {

            System.out.println(n + " is not a Pronic Number.");
        }
    }

}

 


Output


Scenario 1:

Enter a number : 10
10 is not a Pronic Number.

Scenario 2:

Enter a number : 6
6 is a Pronic Number.

 


Video Explanation


This video helps to understand flowchart and program which written in the above steps. There are various ways to write a program and we are not covering all of them as this is just for practice. Please post your program in the comment box so other can utilize it.

work in progress

Leave a Reply

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