写点什么

2021-07-22 Java 练习题,kafka 数据存储原理

用户头像
极客good
关注
发布于: 刚刚

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


【一线大厂Java面试题解析+核心总结学习笔记+最新架构讲解视频+实战项目源码讲义】
浏览器打开:qq.cn.hn/FTf 免费领取
复制代码


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;

用户头像

极客good

关注

还未添加个人签名 2021.03.18 加入

还未添加个人简介

评论

发布
暂无评论
2021-07-22 Java练习题,kafka数据存储原理