Created
June 9, 2015 18:32
-
-
Save go-ive/9315cb311ef012dd937c to your computer and use it in GitHub Desktop.
PrimeChecker
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
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