Skip to content

Instantly share code, notes, and snippets.

@go-ive
Created June 9, 2015 18:32
Show Gist options
  • Save go-ive/9315cb311ef012dd937c to your computer and use it in GitHub Desktop.
Save go-ive/9315cb311ef012dd937c to your computer and use it in GitHub Desktop.
PrimeChecker
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a number to check if it's prime:");
int possiblePrime = scanner.nextInt();
boolean isPrime = true;
for (int i = 2; i < possiblePrime; i++) {
int remainder = possiblePrime % i;
if (remainder == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
System.out.println(possiblePrime + " is a prime number.");
} else {
System.out.println(possiblePrime + " is not prime.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment