Skip to content

Instantly share code, notes, and snippets.

@joywilliamjoy
Created November 7, 2015 17:47
Show Gist options
  • Save joywilliamjoy/ea1b7a5301774c78a418 to your computer and use it in GitHub Desktop.
Save joywilliamjoy/ea1b7a5301774c78a418 to your computer and use it in GitHub Desktop.
package Test;
import java.util.Scanner;
public class Test1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("enter a number:");
int a = input.nextInt();
if(a == 2){
System.out.println("2是質數");
}
// int c = (int)Math.sqrt(a);
// if(c <= 1){
// c ++;
// }
// else{
// c = c;
// }
for(int b = 2;b < a; b++){
if(a%b==0){
// boolean isPrime = false;
System.out.println(a+"不是質數");
break;
}
else if(b == a - 1){
// boolean isPrime = true;
System.out.println(a+"是質數");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment