Sunday , 26 February 2017
Home » Class 10 » Java program to check for Pronic Number (Heteromecic Number)

Java program to check for Pronic Number (Heteromecic Number)

Question:

Write a Program in Java to input a number and check whether it is a Pronic Number or Heteromecic Number or not.

Pronic Number : A pronic number, oblong number, rectangular number or heteromecic number, is a number which is the product of two consecutive integers, that is, n (n + 1).

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

Programming Code:

/**
* The class HarshadNumber inputs a number and checks if it a Pronic Number or not
* @author : www.guideforschool.com
* @Program Type : BlueJ Program - Java
*/

import java.util.*;
class PronicNumber
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        
        System.out.print("Enter a number : ");
        int n = sc.nextInt();
        int flag = 0;
   
        for(int i=0; i<n; i++)
        {
            if(i*(i+1) == n)
            {
                flag = 1;
                break;
            }
        }
        
        if(flag == 1)
            System.out.println(n+" is a Pronic Number.");
        else
            System.out.println(n+" is not a Pronic Number.");      
    }
}

Alternate Programming Code:

/**
* The class HarshadNumber inputs a number and checks if it a Pronic Number or not
* @author : www.guideforschool.com
* @Program Type : BlueJ Program - Java
*/

import java.util.*;
class PronicNumber
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        
        System.out.print("Enter a number : ");
        int n = sc.nextInt();
        int k = (int)(Math.sqrt(n));
        if(k*(k+1)==n)
            System.out.println(n+" is a Pronic Number.");
        else
            System.out.println(n+" is not a Pronic Number.");      
    }
}

Output:

Enter a number : 110
110 is a Pronic Number.

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

Enter a number : 342
342 is a Pronic Number.

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

Check Also

[Question 2] ISC 2017 Computer Practical Paper Solved – Quiz Result

Solution of Program 2 of ISC 2017 Computer Science Paper 2 (Practical) Exam. Java program to input the answers of each participant row-wise and calculate their marks

7 comments

  1. Very Helpfull site for me

  2. excellent site……….

  3. What is the purpose of using variable flag…?

    • Since we are terminating the loop when pronic condition is satisfied, we are changing the value of flag which will let us know whether the loop terminated on the satisfaction of the condition of pronic or it terminated normally on the completion of the loop

  4. Absolute knowledge reloaded

  5. Sourish Mukherjee

    wonderful site…………..

Leave a Reply to Ritvik Sharma Cancel reply

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