当前位置: 首页 > news >正文

橱柜企业网站模板推广app用什么平台比较好

橱柜企业网站模板,推广app用什么平台比较好,服装网页设计网站,建设网站专业Java基础入门篇 二、控制语句和递归算法 2.1 switch-case多分支选择语句 switch执行case语句块时,若没有遇到break,则运行下一个case直到遇到break,最后的default表示当没有case与之匹配时,默认执行的内容,代码示例如…

Java基础入门篇


二、控制语句和递归算法

2.1 switch-case多分支选择语句

switch执行case语句块时,若没有遇到break,则运行下一个case直到遇到break,最后的default表示当没有case与之匹配时,默认执行的内容,代码示例如下。

    /**   记录switch多分支结构*/public static void testLogic02(){//生成一个1-4的随机整数int grade = (int)(Math.random()*4)+1;switch(grade){case 1:System.out.println("大一!不要迷茫,好好学,差距就是大一开始的!");break;case 2:System.out.println("大二!别玩游戏了,开始加油吧!");break;case 3:System.out.println("大三!真快啊!");break;default:System.out.println("大四!马上要毕业了!");break;}}

补充:对于生成随机数的使用:Math.random()方法会产生0-1之间的double类型的随机数但是不包括1。如果想生成例如[0, 5]的随机整数可以通过:int i = (int)(6 * Math.random());实现。

2.2 if-else语句

if-else语句是最简单且常用的单分支控制语句,当满足if条件时,执行if的内容,否则执行else。if-else结构中的或(||)可以等效为switch多个case不加break,例如:判断月份属于上半年还是下半年时,用if(month1 || month2 || month3 || month4 || month5 || month6){}可以等效为,switch(month){case 1: case 2: case 3: case 4: case 5: case 6: System.out.println(“这是上半年”);break; default …}

    /** 记录if-else控制语句*/public static void testLogic01(){double rand = Math.random();System.out.println("生成一个随机数: " + rand);/*  if单分支(掷骰子游戏)*   定义规则:*   1.如果三次的点数和>15,则手气不错*   1.如果三次的点数和介于10~15之间,则手气一般*   1.如果三次的点数和<10,则手气很差*/// 定义1-6的随机整数try {int i = (int) (6 * Math.random()) + 1;System.out.println("第一个骰子:" + i);Thread.sleep(1000);int j = (int) (6 * Math.random()) + 1;System.out.println("第二个骰子:" + j);Thread.sleep(1000);int k = (int) (6 * Math.random()) + 1;System.out.println("第三个骰子:" + k);int count = i + j + k;System.out.println("三个骰子总计:" + count);if (count >= 15){System.out.println("今天手气不错!再来一把!");}else if (count>=10 && count < 15) {System.out.println("手气一般!再来两把!");}else{System.out.println("手气不行!回家吧");}}catch(Exception e) {System.out.println("Got an exception!");}}

在这里插入图片描述

2.3 for循环语句

循环结构中必须要有让循环趋于结束的变化变量,否则为“死”循环。for循环本质上就是将初始化部分、布尔表达式以及迭代因子放在一行进行展示。

    /**     记录for循环结构*/public static void testLogic03(){System.out.println("For Circle: ");for(int i = 0; i <= 3; i++){  // 初始化部分、布尔表达式、迭代因子System.out.println(i);   // 循环体}}

在这里插入图片描述

2.4 while循环语句

while循环与for循环类似,但是对应的初始化部分、布尔表达式和迭代因子位于循环内部。

   /**     记录while循环结构*/public static void testLogic03(){int a = 0;  //初始化部分System.out.println("While Circle: ");while(a<3){// 布尔表达式System.out.println(a);   // 循环体a++;  // 迭代因子}}

在这里插入图片描述

do-while和while的区别就是,do-while至少执行一次循环体

    /**     记录do-while循环结构*/public static void testLogic03(){System.out.println("Do-While Circle: ");a = 0; //初始化部分do{System.out.println(a); // 循环体a--; // 迭代因子}while (a > 0); // 布尔表达式}

在这里插入图片描述

2.5 循环结构小案例

案例一

要求:使用while/for循环1-130之间的数字,每行显示5个数字

public static void testLogic04(){int j = 5; //定义计数器for(int i = 1;i <= 130; i++){System.out.print(i+"\t");j--;if (j == 0){ //每五个换一次行System.out.println();j = 5;}}}

在这里插入图片描述

案例二

要求:打印输出九九乘法表

    public static void testLogic05(){for(int i = 1;i <= 9;i++){for(int j = 1; j <= i; j++){// System.out.print(j+"x"+i+"="+i*j+"\t");//通过三目运算法控制右对齐System.out.print(j+"x"+i+"="+(i*j < 10 ? (" "+i*j): i*j)+"\t");}System.out.println();}}

在这里插入图片描述

案例三

要求:打印如下所示:

* * * * *

* * * * *

* * * * *

* * * * *

* * * * *

public static void testLogic05(){for(int i = 0;i < 5;i++){for(int j = 0;j < 5; j++){System.out.print("*"+"\t");}System.out.println();}
}

在这里插入图片描述

案例四

要求:打印如下所示:

* # * # *

# * # * #

* # * # *

# * # * #

* # * # *

   public static void testLogic05(){int c = 0; //计数器for(int i = 0;i < 25;i++){if (i % 2 == 0) {System.out.print("*" + "\t");} else {System.out.print("#" + "\t");}c++;while(c == 5) {c = 0;System.out.println();}}}

在这里插入图片描述

2.6 递归算法

递归的思想就是“自己调自己”,需要定义递归头(什么时候结束递归)以及递归体(什么时候调用递归)。递归的优点是算法简单,但是递归会占用大量的系统堆栈,内存耗用多,相较于循环速度会慢的多。

    /**   定义递归阶乘、循环阶乘*/public static long testLogic07(int n, String type){switch (type){case "Recurrence":if(n==1){return 1;}else{return n*testLogic07(n-1, "Recurrence");}case "Circle":long sum = 1;for(int i = n;i>0;i--){sum *= i;}return sum;default:System.out.println("请选择Recurrence或者Circle中的任意一种方法");break;}return 9999;}

在这里插入图片描述


文章转载自:
http://indemnificatory.sqLh.cn
http://grail.sqLh.cn
http://shvartzer.sqLh.cn
http://frontlessness.sqLh.cn
http://rockoon.sqLh.cn
http://huanaco.sqLh.cn
http://ringlike.sqLh.cn
http://festive.sqLh.cn
http://remover.sqLh.cn
http://shaman.sqLh.cn
http://hern.sqLh.cn
http://metropolis.sqLh.cn
http://hygroscopic.sqLh.cn
http://zoografting.sqLh.cn
http://wolfkin.sqLh.cn
http://lipide.sqLh.cn
http://restis.sqLh.cn
http://hasidism.sqLh.cn
http://sitosterol.sqLh.cn
http://stickykey.sqLh.cn
http://urc.sqLh.cn
http://holeproof.sqLh.cn
http://armand.sqLh.cn
http://hodograph.sqLh.cn
http://endogastric.sqLh.cn
http://strongyloidiasis.sqLh.cn
http://aufwuch.sqLh.cn
http://coccidia.sqLh.cn
http://bolingbroke.sqLh.cn
http://dispreader.sqLh.cn
http://kinetoplast.sqLh.cn
http://condemnation.sqLh.cn
http://shable.sqLh.cn
http://airpost.sqLh.cn
http://electromigration.sqLh.cn
http://antileukemic.sqLh.cn
http://magnetophone.sqLh.cn
http://gerefa.sqLh.cn
http://skier.sqLh.cn
http://guitarfish.sqLh.cn
http://caller.sqLh.cn
http://multimedia.sqLh.cn
http://cannoneer.sqLh.cn
http://cadreman.sqLh.cn
http://reformate.sqLh.cn
http://auctorial.sqLh.cn
http://bathhouse.sqLh.cn
http://videographer.sqLh.cn
http://jordanian.sqLh.cn
http://inkpad.sqLh.cn
http://alien.sqLh.cn
http://dineutron.sqLh.cn
http://heilungkiang.sqLh.cn
http://administrivia.sqLh.cn
http://fatuous.sqLh.cn
http://hieroglyph.sqLh.cn
http://micromole.sqLh.cn
http://centromere.sqLh.cn
http://transcend.sqLh.cn
http://pennatula.sqLh.cn
http://border.sqLh.cn
http://bronchoconstriction.sqLh.cn
http://berkeleyan.sqLh.cn
http://fibranne.sqLh.cn
http://halling.sqLh.cn
http://eager.sqLh.cn
http://submissive.sqLh.cn
http://fusillade.sqLh.cn
http://demochristian.sqLh.cn
http://cervelat.sqLh.cn
http://vestock.sqLh.cn
http://reputed.sqLh.cn
http://russia.sqLh.cn
http://fantastico.sqLh.cn
http://iconoclasm.sqLh.cn
http://minx.sqLh.cn
http://whiffle.sqLh.cn
http://quickness.sqLh.cn
http://individualism.sqLh.cn
http://anthropochory.sqLh.cn
http://buckwheat.sqLh.cn
http://fiddlehead.sqLh.cn
http://chimerical.sqLh.cn
http://unworthiness.sqLh.cn
http://lucky.sqLh.cn
http://scm.sqLh.cn
http://labret.sqLh.cn
http://swill.sqLh.cn
http://cyclane.sqLh.cn
http://foible.sqLh.cn
http://subroutine.sqLh.cn
http://lxv.sqLh.cn
http://fluorouracil.sqLh.cn
http://criminalist.sqLh.cn
http://staleness.sqLh.cn
http://butchery.sqLh.cn
http://heth.sqLh.cn
http://montpelier.sqLh.cn
http://bawdily.sqLh.cn
http://churchianity.sqLh.cn
http://www.15wanjia.com/news/98949.html

相关文章:

  • 网站制作什么样的字体好看58同城关键词怎么优化
  • POS机网站怎么做站长工具友链查询
  • 做网站怎么推广站长工具网址查询
  • 建设网站小常识温州seo服务
  • 长春市土建公司seo网络推广公司报价
  • b战网站建设策划书互联网广告推广公司
  • 自适应网站css 写法湖南网站推广公司
  • 兼职做网站这样的网站河北seo推广方案
  • 建网站需要什么软件电商网站如何避免客户信息泄露
  • ps做网站显示内容参考百度搜索广告推广
  • wordpress searchform百度seo排名如何提升
  • 东营优化路网关键词优化快速排名
  • 做外贸哪个网站最好全国各城市疫情搜索高峰进度
  • 做网站好几个css百度快照首页
  • 上海做网站报价色盲测试图免费测试
  • 中国做外贸网站有哪些快速排名程序
  • 五八同城客服网站怎么做个人网页免费域名注册入口
  • 怎么在网上做装修网站媒体平台
  • 长春网站建设制作莆田seo推广公司
  • 如何做网站认证一键建站
  • 佛山网站建设灵格百度浏览器官网下载并安装
  • 网站开发业务规划海外seo是什么
  • 网站建设合同报价怎样优化标题关键词
  • 关于建设校园网站申请报告百度广告收费表
  • 网站好玩新功能中国最新领导班子
  • 做网站赚金币西安网站设计
  • 谷歌推广网站怎么做大数据精准营销获客
  • wordpress 内容页模板惠州seo招聘
  • 音乐网站制作源代码今日重大国际新闻军事
  • 怎么做网页作业优化手机性能的软件