Wap in java to check pronic number or not.
Answers
import java.util.*;
class pronic_number
{
public void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number to check whether it is pronic number or not");
int n=sc.nextInt();
int flag=0;
for(int i=1;i<=n;i++)
{
if(i*(i+1)==n)
{
flag=1;
break;
}
}
if(flag==0)
{
System.out.println(n+" is not a pronic number");
}
if(flag==1)
{
System.out.println(n+" is a pronic number");
}
}
}
Answer:
- A pronic number is a type of number which is a product of any two consecutive integers.
- A pronic number is a type of number which is a product of any two consecutive integers.It's a Java program i.e. the following program is written in Java programming language.
import java.util.Scanner;
public class PronicNumber
{
public static void main(String brain[])
{
Scanner promo=new Scanner(System.in);
System.out.println("Enter a number to be checked.");
int n=promo.nextInt();
for(int k=1;k<=n;k++)
{
if(n%k==0)
{
if((k+1)*i==n||(k-1)*i==n)
{
System.out.println("Entered number is Pronic.");
break;
}
else
{
System.out.println("No, the number is not Pronic number.");
break;
}
}
}
}
}