C Programs Tutorials | IT Developer
IT Developer

Java Programs



Share with a Friend

Pronic Number - Java Programs

 
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 × 4
20 = 4 × 5
42 = 6 × 7

import java.util.Scanner; class Pronic{ public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.print("N = "); int n = Integer.parseInt(in.nextLine()); int p = 1; while(p * (p + 1) < n) p++; if(p * (p + 1) == n) System.out.println("Pronic number"); else System.out.println("Not a Pronic number"); } }

Output

 
 OUTPUT 1: 
 N = 12
Pronic number

 OUTPUT 2: 
 N = 20
Pronic number