a007.
判斷質數
| From: [163.17.20.100] |
發表日期
:
2012-11-14 20:38
package javaapplication10;
import java.util.Scanner;
public class JavaApplication10 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner g = new Scanner(System.in);
int b,q;
while(g.hasNextInt()){
b = g.nextInt();
q=0;
for(int i=3; i<b;i+=2){
if(b%i==0 ||b%2==0){q++;break;}
}
if(q!=0){System.out.println("非質數");}
else{System.out.println("質數");}
}
}
}