forked from sujana-kamasany/javacodes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pronic Number Program in Java sujana-kamasany#83
- Loading branch information
1 parent
5ae4a15
commit 6073318
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |