Skip to content

Commit

Permalink
Create PronicNumber.java
Browse files Browse the repository at this point in the history
 Pronic Number Program in Java sujana-kamasany#83
  • Loading branch information
ioannakatsanou committed Apr 7, 2022
1 parent 5ae4a15 commit 6073318
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Basics/PronicNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.util.Scanner;

public class PronicNumber {

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Input a number : ");
int n = in.nextInt();
System.out.println(isPronic(n) == true ? n + " is a Pronic Number." : n + " is not a Pronic Number");
}

/**
* Returns true if number is pronic, and false otherwise
*
* @param num
* @return
*/
private static boolean isPronic(int num) {
for (int i = 0; i < num; i++) {
if (i * (i + 1) == num)
return true;
}
return false;
}

}

0 comments on commit 6073318

Please sign in to comment.