1、打印九九乘法表
public class MultiTable {
public static void main(String[] args) {
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
// 不换行打印数据
System.out.print(i + " * " + j + " = " + i * j + “\t”);
}
// 打印完一行进行换行
System.out.println();
}
}
}
/2、判断1-100之间有多少个素数并输出所有素数。
public class PrimeNum {
public static void main(String[] args) {
int count = 0;
for (int j = 1; j <= 100; j++) {
if (isPrime(j)) {
System.out.print(j + " ");
count++;
if (count % 8 == 0) {
System.out.println();
}
}
}
}
private static boolean isPrime(int n) {
boolean flag = true; // flag:返回值默认true,表示是素数
if (n == 1){
flag = false;
}else {
for (int i = 2; i <