⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sushu.java

📁 可以为用户输出两个指定的整数之间的素数,并具有输入检错功能.
💻 JAVA
字号:
import java.util.Scanner;

public class Sushu
	{

		/**
		 * @param args
		 */
		public  boolean isSushu(int temp)
			{
				boolean flag=true;
				int i=2;
				if(temp==2)
					return flag = true;
				while(i<=Math.sqrt(temp)&&temp%i!=0)
					i++;
				if(i>temp) flag = true;
				if(temp%i==0) flag= false;
				return flag;
				
			}
		public static void main(String[] args)
			{
				System.out.println("Input an Integer numlow: ");
				//System.out.println("Input an Integer numhigh: ");
				Scanner in = new Scanner(System.in);
				int numlow = in.nextInt();
				System.out.println("Input an Integer numhigh: ");
				int numhigh = in.nextInt();
				Sushu ss = new Sushu(); 
				if(numlow<numhigh)
					{
						for(int i=numlow;i<=numhigh;i++)
							if(ss.isSushu(i))
								System.out.print(i+" ");
					}
				else
					System.out.print("输入错误!")	;				

			}

	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -