java 生成两个数之间的素数
//print all prime numbers within a number import java.util.Scanner; public class Numbers { public static void main(String[] args) { int beg, end; Scanner ip = new Scanner(System.in); System.out.print("Enter the beginning value: "); beg = ip.nextInt(); System.out.print("Enter the ending value: "); end = ip.nextInt(); for (int i = beg; i <= end; i++) { if (isPrime(i)) System.out.print(i + " "); } ip.close(); } private static boolean isPrime(int num) { for (int i = 2; i <= Math.sqrt(num); i++) { if (num % i == 0) return false; } return true; } } OUTPUT: Enter the beginning value: 50 Enter the ending value: 100 53 59 61 67 71 73 79 83 89 97