pronic number in java

Solutions on MaxInterview for pronic number in java by the best coders in the world

showing results for - "pronic number in java"
Alyssa
02 Sep 2017
1import java.util.Scanner;
2public class PronicNumberJava
3{
4   public static void main(String[] args)
5   {
6      Scanner sc = new Scanner(System.in);
7      System.out.print("Please input a number: ");
8      int number = sc.nextInt();
9      int pronic = 0;
10      for(int p = 0; p < number; p++)
11      {
12         if(p * (p + 1) == number)
13         {
14            pronic = 1;
15            break;
16         }
17      }
18      if(pronic == 1)
19      {
20         System.out.println(number + " is a pronic number.");
21      }
22      else
23      {
24         System.out.println(number + " is not a pronic number.");
25      }
26      sc.close();
27   }
28}