C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

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.


Liked this article? Do share with your friends :)


COMMENTS