2021-07-22 Java 练习题,kafka 数据存储原理
public static void topic() {
System.out.println("请输入你想运行题目的序号:");
Scanner s = new Scanner(System.in);
int t = s.nextInt();
switch (t) {
case 1:
topic01();
break;
case 2:
topic02();
break;
case 3:
topic03();
break;
case 4:
topic04();
break;
case 5:
topic05();
break;
case 6:
topic06();
break;
case 7:
topic07();
break;
case 8:
topic08();
break;
case 801:
topic0801();
break;
}
}
public static void topic01() {
int sum = 0;
for (int i = 1; i <= 100; i++) {
if (i % 7 == 0) sum += i;
}
System.out.println("1 到 100 能被 7 整除的数字和为" + sum);
}
public static void topic02() {
System.out.println("请输入年份:");
Scanner s = new Scanner(System.in);
int year = s.nextInt();
System.out.println("请输入月份:");
int month = s.nextInt();
System.out.println("请输入日份:");
int day = s.nextInt();
int sum = 0;
for (int i = 0; i < month; i++) {
switch (i) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
sum += 31;
break;
case 4:
case 6:
case 9:
case 11:
sum += 30;
break;
case 2:
if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) {
sum += 29;
} else {
sum += 28;
}
}
}
sum += day;
System.out.println("这一天是这一年的第" + sum + "天");
}
public static void topic03() {
double molecular = -4;
double denominator = 1;
double PI = 0;
int frequency = -1;
while (PI >= 3.1415927 || PI <= 3.1415926) {
molecular = -molecular;
PI += molecular / denominator;
denominator += 2;
frequency++;
}
System.out.println("一共需要运行" + frequency + "次");
}
public static void topic04() {
int height = 7;
int day = 0;
while (height != 0) {
day++;
height -= 3;
if (height != 0) {
height += 2;
}
}
System.out.println(day);
}
public static void topic05() {
int a = 0;
int b = 0;
int c = 0;
for (int i = 1; i <= 10; i++) {
System.out.println("请输入第" + i + "个字符");
Scanner s = new Scanner(System.in);
String str = s.nextLine();
Pattern p1 = compile("[a-zA-Z]");
Pattern p2 = compile("[0-9]");
Matcher m1 = p1.matcher(str);
Matcher m2 = p2.matcher(str);
if (m1.find()) {
a++;
} else if (m2.find()) {
b++;
} else {
c++;
}
}
System.out.println("你输入了" + a + "个字母、" + b + "个数字、" + c + "个其他字符");
}
public static void topic06() {
int i = 0;
int j = 0;
for (i = 1; i <= 9; i++) {
for (j = 1; j <= i; j++) {
//print 是不换行输出;而 println 是换行输出。该处使用 print 输出
Sy
stem.out.println(i + "*" + j + "=" + i * j);
}
}
}
public static void topic07() {
System.out.println("请输入你要求的最大阶乘:");
Scanner s = new Scanner(System.in);
int max = s.nextInt();
long sum = 0;
评论