Q:

Java program to check Pronic Number

belongs to collection: Java Basic Programs

0

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.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to check whether the number is IMEI N... >>
<< Java program to check Harshad Number...