Write a java program to input and check whether the number is a pronic no. or not.
Answers
Answered by
6
class pronic
{
public static void main(String args [])
{
Scanner sc = new Scanner( System.in);
System.out.println("Enter a number");
int n,i
n= sc.nextInt();
for(i=1;i<n;i++)
if(i*(i+1)==n)
{i=0;break}
if(i==0)
System.out.println("pronic number");
else
System.out.println("not a pronic number.");
}}
{
public static void main(String args [])
{
Scanner sc = new Scanner( System.in);
System.out.println("Enter a number");
int n,i
n= sc.nextInt();
for(i=1;i<n;i++)
if(i*(i+1)==n)
{i=0;break}
if(i==0)
System.out.println("pronic number");
else
System.out.println("not a pronic number.");
}}
Answered by
6
- A pronic number is a type of number which is a product of any two consecutive integers.
import java.util.Scanner;
public class PronicNumber
{
public static void main(String args[])
{
Scanner obj=new Scanner(System.in);
System.out.println("Enter a number.");
int n=obj.nextInt();
for(int i=1;i<=n;i++)
{
if(n%i==0)
{
if((i+1)*i==n||(i-1)*i==n)
{
System.out.println("Entered number is Pronic.");
break;
}
else
{
System.out.println("No, the number is not Pronic.");
break;
}
}
}
}
}
Similar questions