ex030211.java

来自「我在学习JAVA的讲义」· Java 代码 · 共 34 行

JAVA
34
字号
import java.io.*;
public class Ex030211{
	static boolean isPrimeNumber(int x){
		if (x==1) 
			return false;
		for (int i=2; i<x;i++){
			if (x%i==0){
				return false;
			}
		}
		return true;
	}

	public static void main(String[] args){
		int x=0;
		Reader ir = new InputStreamReader(System.in);
		BufferedReader r = new BufferedReader(ir);
		String sc="";
		System.out.print(" x = ");
		try{
			sc = r.readLine();
		}catch (IOException e){}
		try{
			x=Integer.parseInt(sc);
		}catch (NumberFormatException e){
			System.out.println("输入的数据不是整数");
			System.exit(1);
		}
		if (isPrimeNumber(x))
			System.out.println(""+x+" is a Prime Number");
		else
			System.out.println(""+x + " is not a Prime Number");
	}
}

⌨️ 快捷键说明

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