Home » Java programs » Java basic programs

Java program to check Pronic Number



In this java program, we are going to check whether a given number is Pronic Number or not.
Submitted by Chandra Shekhar, on January 18, 2018

Given a number, we have to check that the entered number is Pronic Number or not.

A number is said to be a Pronic number if it is having the product of consecutive two numbers.

Example:

    Input: 420
    Output:
    420 – Is a Pronic Number.

Program to check whether the given number is Pronic Number or not in java

import java.util.Scanner;

public class CheckPronicNumber 
{
	public static void main(String args[])
    {
		// create object of scanner class
        Scanner sc = new Scanner(System.in);
         
        // enter the number here.
        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;
            }
        }
        
        // check here for Pronic number.
        if(flag == 1)
            System.out.println(n+" is a Pronic Number.");
        else
            System.out.println(n+" is not a Pronic Number.");      
    }
}

Output

First run:
Enter a number : 16542
16542 is not a Pronic Number.

Second run:
Enter a number : 462
462 is a Pronic Number.





Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.