Skip to content

Instantly share code, notes, and snippets.

@mikestratton
Last active August 29, 2015 14:20
Show Gist options
  • Save mikestratton/71f69a04d71acfb862f4 to your computer and use it in GitHub Desktop.
Save mikestratton/71f69a04d71acfb862f4 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
class primeNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your input number:");
int n = scanner.nextInt();
int j = 2;
int result = 0;
while (j <= n / 2)
{
if (n % j == 0)
{
result = 1;
}
j++;
}
if (result == 1)
{
System.out.println("Not a prime number");
}
else
{
System.out.println("Input number is a prime number");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment