Pronic Number

pronic number is a number which is the product of two consecutive integers, that is, a number of the form 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. 

import java.util.*;

class pronic

{//class pronic opens

    public static void main(String[]args)

    {//main method opens

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter a no");

        int n=sc.nextInt();//variable n to accept the no

        int sq=(int)Math.sqrt(n);//variable sq to store the square root of the no

        int p=sq*(sq+1);//variable p stores the product of the square root with the next number of the square root 

        if(p==n)

        System.out.println("It is  pronic no");

        else

        System.out.println("It is not a pronic no");

    }//main method closes

}//class closes


No comments:

Post a Comment

any problem in any program comment:-

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...