Question
find whether the given number is a pronic number.
(The pronic number can be defined as the number which is a product of two consecutive numbers. )
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
import java.util.Scanner;
public class PronicNumbers
{
public static void main(String[] args)
{
int num=0, i=0;
boolean flag=false;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
num=sc.nextInt();
for(i=0;i<=num;i++)
{
if((i*(i+1))==num)
{
flag=true;
break;
}
}
if(flag==true)
{
System.out.print(num + " is a pronic number ");
}
else
{
System.out.print(num + " is not a pronic number ");
}
}
}