java基础11节-练习
2021/11/18 11:10:16
本文主要是介绍java基础11节-练习,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
package hello; import java.util.Scanner; public class hello{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入一个星期数:"); int week = sc.nextInt(); if (week<1 || week>7) { System.out.println("您输入有误"); } else if (week==1) { System.out.println("跑步"); }else if (week==2) { System.out.println("游泳"); }else if (week==3) { System.out.println("慢走"); }else if (week==4) { System.out.println("动感单车"); }else if (week==5) { System.out.println("拳击"); }else if (week==6) { System.out.println("爬山"); }else if (week==7) { System.out.println("好好吃一顿"); } } }
package hello; import java.util.Scanner; public class hello{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入一个星期数:"); int week = sc.nextInt(); switch (week) { 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; default: System.out.println("你输入有误"); } } }
package hello; import java.util.Scanner; public class hello{ public static void main(String[] args) { for (int x = 1;x<=100;x++) { if (x%10==7 || x/10%10==7 || x%7==0) { System.out.println(x); } } } }
package hello; import java.util.Scanner; public class hello{ public static void main(String[] args) { int[] arr = new int[20]; arr[0] = 1; arr[1] = 1; for (int x = 2;x<arr.length;x++) { arr[x] = arr[x-2] + arr[x-1]; } System.out.println(arr[19]); } }
这篇关于java基础11节-练习的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-30掌握这些技巧,助你成为顶级产品经理
- 2024-11-30通义灵码 x 函数计算:构建高效开发流程,加速项目交付
- 2024-11-30高效团队的三大特质:高协作、高执行、高凝聚力
- 2024-11-30[开源]10.3k star!一款高颜值的后台管理系统,好用!
- 2024-11-30java最新版本是什么,有什么特性?-icode9专业技术文章分享
- 2024-11-30[开源]27.8K star!这款 Postman 替代工具太火了!
- 2024-11-30Gzip 压缩入门教程:轻松掌握文件压缩技巧
- 2024-11-29开源工具的魅力:让文档管理更“聪明”
- 2024-11-29Release-it开发入门教程
- 2024-11-29Rollup 插件入门教程:轻松掌握模块打包