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

电脑网站怎么做的液压产品做哪个网站好

电脑网站怎么做的,液压产品做哪个网站好,黄页88推广多少钱,企业招聘信息发布平台一、分支结构 2.1 if 语句 【练习】2.1.1 小明,如果这次考到90分以上,给你奖励一个大鸡腿,否则奖你一个大嘴巴子 int score 92;if(score > 90){System.out.println("吃个大鸡腿!!!");}else{System.out.println("挨大嘴…

一、分支结构

2.1 if 语句

【练习】2.1.1

      小明,如果这次考到90分以上,给你奖励一个大鸡腿,否则奖你一个大嘴巴子

  int score = 92;if(score >= 90){System.out.println("吃个大鸡腿!!!");}else{System.out.println("挨大嘴巴子!!!");}
【练习】2.1.2

      比如:考虑到学生自尊,不公开分数排名,因此:

      分数在 [90, 100] 之间的,为优秀

      分数在 [80, 90) 之前的,为良好

      分数在 [70, 80) 之间的,为中等

      分数在 [60, 70) 之间的,为及格

      分数在 [ 0, 60) 之间的,为不及格

      错误数据 按照上述办法通知学生成绩

  if(score >= 90){System.out.println("优秀");}else if(score >= 80 && score < 90){System.out.println("良好");}else if(score >= 70 && score < 80){System.out.println("中等");}else if(score >= 60 && score < 70){System.out.println("及格");}else if(score >= 0 && score < 60){System.out.println("不及格");}else{System.out.println("错误数据");}
  【练习】2.1.3

     判断一个数字是奇数还是偶数 

  int num = 10;if (num % 2 == 0) {System.out.println("num 是偶数");} else {System.out.println("num 是奇数");}
  【练习】2.1.4

      判断一个年份是否为闰年

  int year = 2000;if (year % 100 == 0) {// 判定世纪闰年if (year % 400 == 0) {System.out.println("是闰年");} else {System.out.println("不是闰年");}} else {// 普通闰年if (year % 4 == 0) {System.out.println("是闰年");} else {System.out.println("不是闰年");}}

  2.2 switch 语句

      【练习】2.2.1根据 day 的值输出星期几

  int day = 1;switch(day) {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("输入有误");break;}

二、循环结构

  3.1 while 循环

  【练习】3.1.1

      计算 1 - 100 的和

  int n = 1;int result = 0;while (n <= 100) {result += n;n++;}System.out.println(num);// 执行结果5050
  【练习】3.1.2

      计算 1! + 2! + 3! + 4! + 5!

  int num = 1;int sum = 0;// 外层循环负责求阶乘的和while (num <= 5) {int factorResult = 1;int tmp = 1;// 里层循环负责完成求阶乘的细节.while (tmp <= num) {factorResult *= tmp;tmp++;}sum += factorResult;num++;}System.out.println("sum = " + sum);

3.2 break

  【练习】3.2.1

      找到 100 - 200 中第一个 3 的倍数  

  int num = 100;while (num <= 200) {if (num % 3 == 0) {System.out.println("找到了 3 的倍数, 为:" + num);break;}num++;}// 执行结果找到了 3 的倍数, 为:102

3.3 continue

  【练习】3.3.1

      找到 100 - 200 中所有 3 的倍数

  int num = 100;while (num <= 200) {if (num % 3 != 0) {num++; // 这里的 ++ 不要忘记! 否则会死循环.continue;}System.out.println("找到了 3 的倍数, 为:" + num);num++;}

3.4 for 循环

  【练习】3.4.1

      计算 1! + 2! + 3! + 4! + 5!

  int sum = 0;for (int i = 1; i <= 5; i++) {int tmp = 1;for (int j = 1; j <= i; j++) {tmp *= j;}sum += tmp;}System.out.println("sum = " + sum);

3.5 do while 循环(了解)

  【练习】3.5.1

      打印 1 - 10

  int num = 1;do {System.out.println(num);num++;} while (num <= 10)

三、猜数字游戏

  import java.util.Random;import java.util.Scanner;;class Test {public static void main(String[] args) {Random random = new Random(); // 默认随机种子是系统时间Scanner sc = new Scanner(System.in);int toGuess = random.nextInt(100);// System.out.println("toGuess: " + toGuess);while (true) {System.out.println("请输入要输入的数字: (1-100)");int num = sc.nextInt();if (num < toGuess) {System.out.println("低了");} else if (num > toGuess) {System.out.println("高了");} else {System.out.println("猜对了");break;}}sc.close();}}

四、总结

      希望大家能够准确完成本篇的练习,独立实现猜数字游戏,制作不易,感谢支持!

http://www.yayakq.cn/news/184257/

相关文章:

  • 全网营销型网站 新闻网站后台发邮件
  • 网站开发思维导图金融类网站源码
  • 重庆手机微信网站建设小程序游戏开发成本
  • 公司网站域名cn和com上海浦东新区
  • 为什么要建设o2o网站酒店网站建设考虑哪些因素
  • 客户做网站需要提供什么jsp网站开发公司
  • 阳江公司做网站uc下一页
  • 快速网站搭建商业网站怎么做
  • 网站后台发邮件注册文化传媒公司流程和费用
  • 网站如何做sem国外优秀app设计网站有哪些
  • 备案期间网站如何把本地网站
  • 百度怎么注册自己的网站网站建设技术是干嘛的
  • 给别人做网站赚钱wordpress更改wp文件夹
  • 桂林市网站建设企业管理咨询包括哪些内容
  • 做英文网站挂谷歌广告河北 全部阳性了
  • 新公司网站建设wordpress 屏蔽中文浏览器
  • 互联网定制产品网站建设旅游网站建议
  • 重庆忠县网站建设公司哪里有网站开发制作培训学校
  • 电脑做网站服务器教程多个wordpress空间互相同步
  • 建设公司网站开发方案网站搭建怎么弄的
  • 北京网站建设 都选万维科技西安淘宝网站建设公司哪家好
  • 订制电子商务网站 价格无锡网站优化价格
  • 大兴企业网站建设建造师
  • 校园招聘网站策划书咸阳做网站的公司有哪些
  • 如何做tiktok的数据排行网站cj联盟wordpress
  • 怎么做视频的网站推广产品的渠道
  • 好的网站建设价格可信网站认证 服务中心
  • 石家庄网站关键词动易网站模版的制作
  • 摄影网站模板下载做网站的软件word
  • 广东手机网站建设报价刷关键词排名seo