sushu.java

来自「可以为用户输出两个指定的整数之间的素数,并具有输入检错功能.」· Java 代码 · 共 43 行

JAVA
43
字号
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 + =
减小字号Ctrl + -
显示快捷键?