Computer Science, asked by sakshamrai420, 11 months ago

Wap in java to check pronic number or not.​

Answers

Answered by Anonymous
17

\huge{\underline{\underline{\textbf{EASIEST CODE :}}}}

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");

}

}

}

\boxed{\boxed{\boxed{\textbf{EXPLANATION}}}}

\bigstar \textsf{The basic logic of the applied program is done by using a break statement and a flag variable .}\\\\\bigstar \textsf{A pronic number is number which is equal to the product of two consecutive numbers .}\\\\\bigstar \mathsf{Example\:is\:72\:which\:is\:the\:product\:of\:8\;and\:9}\\\\\bigstar \textsf{Thus if we just manage to take the square root of the number ,it will be the shortest code .}

Answered by BrainlyPromoter
1

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;

               }

           }            

       }

   }

}

Similar questions