Question
Write a program to input a number and check and print whether it is a Pronic number or not. The pronic number is the number which is the product of two consecutive integers.
Examples:
12 = 3 × 4
20 = 4 × 5
42 = 6 × 7
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 ");
}
}
}