Menu Close

Pronic Number in Java …fcukthecode.com

A pronic number is a number which is the product of two consecutive integers, that is, a number of the form n(n + 1).
The study of these numbers dates back to Aristotle. They are also called oblong numbers, heteromecic numbers, or rectangular numbers; however, the “rectangular number” name has also been applied to the composite numbers.

The first few pronic numbers are:

0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462
(sequence A002378 in the OEIS(On-Line Encyclopedia of Integer Sequences) ).

Input:
Enter a number:  110

Output:
Yes
import java.io.*;
import java.util.*;
public class temp{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter a number:  ");
    int n = sc.nextInt();
    int flag = 0;

    for(int i=0; i<n; i++)
    {
        if(i*(i+1) == n)
        {
            flag = 1;
            break;
        }
    }
    if(flag == 1)
        System.out.println("Yes");
    else
        System.out.println("No");
  }
}

INPUT_1:
Enter a number:  110

OUTPUT:
Yes


INPUT_2:
Enter a number:  73

OUTPUT:
No


INPUT_3:
Enter a number:  2

OUTPUT:
Yes


INPUT_4:
Enter a number:  462

OUTPUT:
Yes


INPUT_5:
Enter a number:  72

OUTPUT:
Yes


INPUT_6:
Enter a number:  6

OUTPUT:
Yes


INPUT_7:
Enter a number:  7

OUTPUT:
No


INPUT_8:
Enter a number:  90

OUTPUT:
Yes


ILLUSTRATION

Executed using javac in linux terminal