write a program to input a number and check and print whether it is a pronic number or not.
Answers
Answered by
1
Question:-
Write a program to input a number and check whether it is a pronic number or not.
A number is said to be a pronic number if it is equal to product of two consecutive integers.
Program:-
Here is your program
import java.util.*;
class Pronic
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number: ");
int n=sc.nextInt();
boolean x=false;
for(int i=1;i<=n;i++)
{
if(i*(i+1)==n)
{
x=true;
break;
}
}
if(x)
System.out.println("Number is a pronic number.");
else
System.out.println("Given number is not a pronic number.");
}
}
Similar questions
Hindi,
2 months ago
Math,
2 months ago
Social Sciences,
2 months ago
Science,
5 months ago
English,
5 months ago
Social Sciences,
10 months ago
Social Sciences,
10 months ago