Pronic Number | Write a program in Java to check whether a given number is a Pronic Number or not. | ISC Computer Science | ICSE Computer Application

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).

Image is Unavailable


Algorithm

  1.   Start
  2. x:=0
  3. Print "Enter a number"
  4. Read x
  5. n=(int)Math.sqrt(x)
  6. If n*(n+1)==true, go to step 7 or else go to step 8
  7. Print "The given number is a Pronic Number". Go to step 9.
  8. Print "The given number is not a Pronic Number"
  9. Stop

Program

Buffered Reader

import java.io.*;
class Pronic
{
    int x;
    
    void accept() throws IOException
    {
        BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
        System.out.println("Enter a number");
        x=Integer.parseInt(br.readLine());
    }
    
    boolean isPronic()
    {
        int n=(int)Math.sqrt(x);
        if(n*(n+1)==x)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    void displayt()
    {
        System.out.println("The given number is a Pronic Number");
    }
    
    void displayf()
    {
        System.out.println("The given number is not a Pronic Number");
    }
    
    void main() throws IOException
    {
        accept();
        if(isPronic()==true)
        {
            displayt();
        }
        else
        {
            displayf();
        }
    }
}

Scanner

import java.util.*;
class Pronic
{
    int x;
    
    void accept() 
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter a number");
        x=sc.nextInt();
    }
    
    boolean isPronic()
    {
        int n=(int)Math.sqrt(x);
        if(n*(n+1)==x)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    void displayt()
    {
        System.out.println("The given number is a Pronic Number");
    }
    
    void displayf()
    {
        System.out.println("The given number is not a Pronic Number");
    }
    
    void main() 
    {
        accept();
        if(isPronic()==true)
        {
            displayt();
        }
        else
        {
            displayf();
        }
    }
}

Documentation

Variable Description

Data Type Variable NameDescription
 intTo store the number entered by the user 
 intTo store the square root of the number 

Method Description

Return Type Method NameDescription
 voidaccept() To accept data from the user 
 booleanisPronic() To check if the given number is Pronic or not 
 voiddisplayt() To display the statement if the condition is true 
 voiddisplayf() To display the statement if the condition is false 
 voidmain() To act as an entry gateway for the compiler. 

Output


Image is Unavailable

Image is Unavailable




Share with all ISC Computer Science Students you know.

Comment below with all your program requests and blog suggestions.

Follow us on social media by clicking on these links. 
Instagram : @IscJavaCode
Twitter: @IscCode
Pinterest: @ISCJavaCode
Facebook: @ISCJavaCode


Stay Healthy
Stay Happy
Stay Helpful


Comments

You might also like:

Conversion of Complex Sentences to Simple Sentences

Conversion of Compound Sentences to Complex Sentences.

Conversion of Complex Sentences to Compound Sentences