Write a program to input a number and check and print whether it is a Pronic number or not. (Pronic number is the number which is the product of two consecutive…

ICSE Class 10 Computer Applications PYQ · 2018 Paper · Section B

5Written · 2018 · Section B · 2018 Paper

Write a program to input a number and check and print whether it is a Pronic number or not. (Pronic number is the number which is the product of two consecutive integers)

Examples:
12 = 3 x 4
20 = 4 x 5
42 = 6 x 7

Show SolutionHide Solution↓
import java.util.Scanner;

public class KboatPronicNumber
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the number to check: ");
        int num = in.nextInt();
        
        boolean isPronic = false;
        
        for (int i = 1; i <= num - 1; 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");
    }
}
BlueJ output of KboatPronicNumber.java
← Previous questionNext question →

Browse the free Computer Applications sample bank