Solve Pronic Number Program
- Categories Java
Find if a given number is Pronic number or not.
Pronic Number: it is the product of two consecutive integers, n(n+1).
e.g 56= 7 x 8 .
import java.util.Scanner;
public class PronicNum
{
public static void main(String[] args)
{
System.out.println("Enter the number:");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int fact = 0;
for(int i = 1; i < n; i++)
{
if (n % i == 0)
if (i * (i + 1) == n)
fact = i;
}
if (fact != 0)
System.out.println("Yes");
else
System.out.println("No");
}
You may also like
Single Linked List Programs in Java
28 August, 2021
Implementing Stack using Array in Java
28 August, 2021
Constructor Programs
3 July, 2021