Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create CheckPrime.java #175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions CheckPrime.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
* This program will check if an Input number is a Prime number
*
*/
public class CheckPrime {

public static void main(String[] args) throws IOException {
checkNumber();
}

private static void checkNumber() throws IOException {
System.out.println("Enter any number between 1-100 in Console:");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String input = reader.readLine();
int number = Integer.parseInt(input);
System.out.println("Input Number: " + number);
isPrimeNumber(number);
}

private static boolean isPrimeNumber(int num) {
if (0 == num || 1 == num) {
return false;
}

for (int i = 2; i <= num / 2; ++i) {
if (num % i == 0) {
System.out.println(num + " is not a Prime Number");
return false;
}
}
System.out.println(num + " is a Prime number");
return true;
}
}