본문 바로가기

DEMO CODE/JAVA 기초

[JAVA] Ex003 솟수 판단 소스

반응형

public class HelloCommentMain {

public static void main(String[] args) {

HelloComment hc = new HelloComment();

System.out.printf("2343251은 솟수일까? %b%n", hc.isPri(2343251));

}

}

class HelloComment {

public boolean isPri(int a) {

boolean isP = true;

int b = (int) Math.sqrt(a);

for (int i = 2; i <= b; i++) {

if (a % i == 0) {

isP = false;

break;

} else{

isP = true;

}

}

return isP;

}

}


반응형