Solutions for Class 10 ICSE Logix Kips Computer Applications with BlueJ Java | IT Developer <?php echo $page_title; ?>
IT Developer

Iterative Constructs in Java

Chapter 9

Iterative Constructs in Java

Class 10 - Logix Kips ICSE Computer Applications with BlueJ


Share with a Friend

Java Program: Check Pronic Number


22. Write a program to input a number and check and print whether it is a Pronic number or not. (Pronic number is a number which is the product of two consecutive integers.)
Example:   12 = 3 x 4
                 20 = 4 x 5
                 42 = 6 x 7

Program Title: Check Pronic Number

import java.util.Scanner;

 

public class PronicNumber {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

 

        System.out.print("Enter a number: ");

        int num = sc.nextInt();

        boolean isPronic = false;

 

        for (int i = 0; i <= num / 2; i++) {

            if (i * (i + 1) == num) {

                isPronic = true;

                break;

            }

        }

 

        if (isPronic) {

            System.out.println(num + " is a Pronic Number.");

        } else {

            System.out.println(num + " is NOT a Pronic Number.");

        }

 

        sc.close();

    }

}

Output

Sample Input / Output 1:
Enter a number: 12
12 is a Pronic Number.

Sample Input / Output 2:
Enter a number: 15
15 is NOT a Pronic Number. 

📝 Explanation

  1. A Pronic number is the product of two consecutive integers:
  2. n = i * (i + 1)
  3. Loop runs from i = 0 to num / 2 (because i * (i+1) cannot exceed num)
  4. If we find i * (i+1) == num, the number is pronic.
  5. If no such i exists, the number is not pronic.