import java.util.Scanner; /** * Created by Admin on 2017/3/25. */ public class test01 { public static boolean IsPrime(int n){ if (n<2) return false; if (n==2) return true; if (n>2) for (int i=2;i<=(int)Math.sqrt(n);i++){ if (n%i==0) return false; } return true; } public static void main(String[] args) { int n = 1; Scanner scanner = new Scanner(System.in); while (n !=-1) { n=scanner.nextInt(); if (IsPrime(n)) System.out.println("质数"); else System.out.println("非质数"); } } }
在静态地方调用的函数也应该是静态的