正能量网站地址污的,深圳网站设计有名 乐云践新,手机怎么做优惠券网站,西安网站有哪些手续费JAVA基础题目练习 1. 键盘录入数据#xff0c;比较大小2. 代码重构#xff08;简化代码#xff0c;少做判断#xff09;3. 键盘录入月份的值#xff0c;输出对应的季节4. 获取三个数据中的最大值使用IF语句5. 用switch语句实现键盘录入月份#xff0c;输出对应的季节6. 求… JAVA基础题目练习 1. 键盘录入数据比较大小2. 代码重构简化代码少做判断3. 键盘录入月份的值输出对应的季节4. 获取三个数据中的最大值使用IF语句5. 用switch语句实现键盘录入月份输出对应的季节6. 求出1-100之间奇数和7. 求5的阶乘8. 在控制台输出所有的”水仙花数”9. 在控制台输出满足如下条件的五位数10. 统计1-1000之间同时满足如下条件的数据有多少个11. 在控制台输出九九乘法表12. 综合题目 1. 键盘录入数据比较大小
// 键盘录入数据比较大小/*键盘录入两个数据获取这两个数据中的最大值键盘录入三个数据获取这三个数据中的最大值键盘录入两个数据比较这两个数据是否相等*/Scanner scanner new Scanner(System.in);System.out.println(请输入a1);int a1 scanner.nextInt();System.out.println(请输入a2);int a2 scanner.nextInt();System.out.println(请输入a3);int a3 scanner.nextInt();int maxNum 0;maxNum (a1 a2) ? (a1 a3 ? a1 : a3) : (a2 a3 ? a2 : a3);System.out.println(最大的值为 maxNum);if (a1 a2) {System.out.println(a1等于a2);}if (a1 a3) {System.out.println(a1等于a3);}if (a2 a3) {System.out.println(a2等于a3);}System.out.println(-------------------------------------------------); 2. 代码重构简化代码少做判断 /*if (age 0 | age 150)System.out.println(成精了...);else if (age 18)System.out.println(该用户未成年..);elseSystem.out.println(该用户成年了..);if(age 18); //表示什么都不做代码重构*/System.out.println(请输入age:);int age scanner.nextInt();if (age 0 age 18) {System.out.println(未成年);} else if (age 18 age 150) {System.out.println(已成年);} else {System.out.println(年龄错误);}System.out.println(-------------------------------------------------); 3. 键盘录入月份的值输出对应的季节 System.out.println(请输入月份:);int mounth scanner.nextInt();if (mounth 3 mounth 5) {System.out.println(春);} else if (mounth 5 mounth 8) {System.out.println(夏);} else if (mounth 8 mounth 11) {System.out.println(秋);} else if (mounth 12 || (mounth 1 mounth 3)) {System.out.println(冬);} else {System.out.println(月份错误);}4. 获取三个数据中的最大值使用IF语句 if (a1 a2) {if (a1 a3) {System.out.println(最大的值为a1 a1);} else {System.out.println(最大的值为a3 a3);}} else {if (a2 a3) {System.out.println(最大的值为a2 a2);} else {System.out.println(最大的值为a3 a3);}}5. 用switch语句实现键盘录入月份输出对应的季节
/*用switch语句实现键盘录入月份输出对应的季节*/switch (mounth) {case 1:System.out.println(冬);break;case 2:System.out.println(冬);break;case 3:System.out.println(春);break;case 4:System.out.println(春);break;case 5:System.out.println(春);break;case 6:System.out.println(夏);break;case 7:System.out.println(夏);break;case 8:System.out.println(夏);break;case 9:System.out.println(秋);break;case 10:System.out.println(秋);break;case 11:System.out.println(秋);break;case 12:System.out.println(冬);break;}6. 求出1-100之间奇数和 System.out.println(请输入n来计算1-n之间的奇数和);int n scanner.nextInt();int sum 0;for (int i 1; i n; i) {if (i % 2 ! 0) {sum i;}}7. 求5的阶乘 System.out.println(1-n之间的奇数和为 sum);System.out.println(请输入m来计算m的阶乘);int m scanner.nextInt();int mlt 1;for (int i 1; i m; i) {mlt * i;}System.out.println(m的阶乘为 mlt);8. 在控制台输出所有的”水仙花数”
/*在控制台输出所有的”水仙花数”所谓的水仙花数是指一个三位数其各位数字的立方和等于该数本身。举例153就是一个水仙花数。153 1*1*1 5*5*5 3*3*3*/for (int i 100; i 1000; i) {int bai 0;int shi 0;int ge 0;bai i / 100;shi (i / 10) % 10;ge i % 10;if (i (bai * bai * bai shi * shi * shi ge * ge * ge)) {System.out.println(i 是水仙花数);}}9. 在控制台输出满足如下条件的五位数 /*请在控制台输出满足如下条件的五位数个位等于万位十位等于千位个位十位千位万位百位*/for (int i 10000; i 100000; i) {int ge 0, shi 0, bai 0, qian 0, wan 0;ge i % 10;shi (i / 10) % 10;bai (i / 100) % 10;qian (i / 1000) % 10;wan (i / 10000) % 10;if (gewan shiqian (geshiqianwanbai)){System.out.println(i 满足条件);}}10. 统计1-1000之间同时满足如下条件的数据有多少个 /*请统计1-1000之间同时满足如下条件的数据有多少个对3整除余2对5整除余3对7整除余2*/for (int i 1;i1000;i){if (i%32 i%53 i%72){System.out.println(i满足条件);}} 11. 在控制台输出九九乘法表 /*// 需求在控制台输出九九乘法表*/for(int i1;i9;i){for(int j1;ji;j){System.out.print(i*j(i*j)\t);}System.out.println();}12. 综合题目
小芳的妈妈每天给她2.5元钱她都会存起来但是每当这一天是存钱的第5天或者5的倍数的话她都会花去6元钱 请问经过多少天小芳才可以存到100元钱。 float money 0;int day 0;while(money!100) {day 1;money 2.5;if (money100){break;}if (day 5 | day % 5 0) {money - 6;}}System.out.println(需要存day天存款为money);