java问题代号大全_java问题代码

展开全部

我简单地写了一下:

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();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值