展开全部
我简单地写了一下:
DEMO:import java.util.Scanner;
public class Test_09 {
/**
* 输出九九乘法表
*/
public static void multiplicationTable() {
for (int i = 1; i
for (int j = 1; j <= 10 - i; j++) {
System.out.print(j + "*" + i + "=" + (i * j) + "\t");
}
System.out.println();
}
}
/**
* 判断一个数是否为质e69da5e887aa3231313335323631343130323136353331333431343664数
*
* @param num
* @return 是质数,返回true;否则,返回false
*/
private static boolean isPrimeNumber(int num) {
if (num > 1) {
for (int i = 2; i
if (num % i == 0) {
return false;
}
}
return true;
} else {
return false;
}
}
/**
* 单次输入判断输入的数是否为质数
*/
public static void input() {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个整数:");
if (sc.hasNextInt()) {
int num = sc.nextInt();
if (isPrimeNumber(num)) {
System.err.println(num + "是质数");
} else {
System.err.println(num + "不是质数");
}
}
}
/**
* 循环输入判断输入的数是否为质数,直到输入exit为止
*/
public static void cycleInput() {
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("请输入一个整数或者输入exit退出:");
if (sc.hasNextInt()) {
int num = sc.nextInt();
if (isPrimeNumber(num)) {
System.err.println(num + "是质数");
} else {
System.err.println(num + "不是质数");
}
} else {
String input = sc.next();
if (input.equals("exit")) {
return;
}
}
}
}
public static void main(String[] args) {
Test_09.multiplicationTable();
Test_09.input();
Test_09.cycleInput();
}
}