101 200 之间的素数

package cn.com.test3;
//101  200 之间的素数
public class test2 {

	public static void main(String[] args) {

		int sushu = sushu(101,200);
		System.out.println();
		System.out.println("(101 - 200有"+sushu+"个素数)");
	}
	
	public static int sushu(int x,int y){
		//记录
		int count = 0;
		//判断
		boolean bool = false ;
		//遍历
		for (int i = x; i <= y; i++) {
			
			//判断是否为素数
			for (int k = 2; k < i-1; k++) {
				
				if (i % k == 0) {
					bool = false ;
					break ;
				}else {
					//count++;
					bool = true ;
					
				}
			}
			
			if (bool == true) {
				count ++;
				System.out.print(i);
				System.out.print(" ");
			}
		}
		
		//返回总数
		return count ;
	}
}

 

点赞