Skip to content

Instantly share code, notes, and snippets.

@devetude
Created September 22, 2016 15:12
Show Gist options
  • Save devetude/1670a0db6d9ff3a1d4539f658f255c9b to your computer and use it in GitHub Desktop.
Save devetude/1670a0db6d9ff3a1d4539f658f255c9b to your computer and use it in GitHub Desktop.
소수판별 2 (Check Prime Number 2)
import java.util.Scanner;
/**
* 소수판별 2 (Check Prime Number 2)
*
* @author devetue
*/
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
sc.close();
int res = -1;
int sqrtN = (int) Math.sqrt(N);
for (int i = 2; i < sqrtN; i++) {
if (N % i == 0) {
res = i;
break;
}
}
if (res != -1 || N == 1) {
System.out.println(N + " isn't prime number");
}
else {
System.out.println(N + " is prime number ");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment