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

宜昌市高新区建设局网站南阳教育论坛网站建设

宜昌市高新区建设局网站,南阳教育论坛网站建设,网站规划与建设与安全管理,投稿平台在哪里找1 编码规范——卫语句 表达异常分支时&#xff0c;少用if-else方式。   比如成绩判断中对于非法输入的处理&#xff1a; /*>90 <100 优秀>80 <90 良好>70 <80 一般>60 <70 及格<60 不及格*/Testpu…

1 编码规范——卫语句

  表达异常分支时,少用if-else方式。
  比如成绩判断中对于非法输入的处理:

    /*>=90   <=100      优秀>=80    <90       良好>=70    <80       一般>=60    <70      及格<60              不及格*/@Testpublic void test2() {//int score = 78;//通过Scanner可以实现从控制台输入信息Scanner scanner = new Scanner(System.in);System.out.println("请输入成绩:");int score = scanner.nextInt();if(score < 0 || score > 100) {System.out.println("非法输入");} else if (score >= 90 && score <= 100) {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 {System.out.println("不及格");}}

Java开发手册(黄山版)
  修改后:

    @Testpublic void test2() {//通过Scanner可以实现从控制台输入信息Scanner scanner = new Scanner(System.in);System.out.println("请输入成绩:");int score = scanner.nextInt();//卫语句1if (score < 0 || score > 0) {//异常和正常 要分开System.out.println("Invalid input!");//后面的代码不再执行return;}//卫语句2...//合法输入if (score >= 90 && score <= 100) {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 {System.out.println("不及格");}}

2 循环控制语句(接Day2)

2.2 continue、break
   还是跟C语法相差无几,放个demo了事
   continue:跳出本次循环,继续下一次循环
   break:跳出离他最近的那层循环

@Test//结果: 1 2 4 5
public void test44() {for (int i = 1; i <= 5; i++) {if (i == 3) {continue;}System.out.println(i);}
}@Test//结果: 1 2
public void test45() {for (int i = 1; i <= 5; i++) {if (i == 3) {break;}System.out.println(i);}
}@Test//
public void test46() {//i,j,kfor (int i = 1; i <= 5; i++) {System.out.println("i: " + i);for (int j = 1; j <= 5; j++) {if (j == 3) {break;}System.out.println("j: " + j);}}
}

2.3 双重for循环
   这个也很简单,
   双重for循环:
   外层循环控制行数,数一下有几行就能确定外层循环。
   内层循环控制列数,这一行打印多少个,到底要打印多少个要找出和当前行之间的一个关系。

   还有一些打印金字塔, 各种三角形的题,统一放到下一篇作业博客吧.
2.4 Switch
   这部分当初学的时候没感觉有啥特别的,但是同种情况的case可以合并这个操作是真的有点没记起来,温故知新了。

    import com.sdust.day2.*;@Test//月份 天数public void test2() {Scanner scanner = new Scanner(System.in);Homework day2 = new Homework();System.out.println("please input month: ");int month = scanner.nextInt();if (month < 1 || month > 12) {System.out.println("invalid month");return;}switch (month) {case 1:case 3:case 5:case 7:case 8:case 10:case 12:System.out.println("31days");break;case 4:case 6:case 9:case 11:System.out.println("30days");break;case 2:System.out.println("please input year: ");int year = scanner.nextInt();if (day2.judgeLeapYear(year)) {System.out.println("29days");} else {System.out.println("28days");}default:System.out.println("default");break;}}

昨天写了几个作业题,包括一个闰年判断的题,于是在今天写这部分代码对闰年进行特判的时候心血来潮想直接调用昨天的代码。先是要导包,仿照Scanner输入的形式写了一下,发现还真行,嗯,基础的Java也就那么回事嘛~

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

相关文章:

  • 网站开发设计模板厦门微信商城网站建设
  • 做网站怎么挣钱最快怎么样优化网站seo
  • 公司创建网站要多少钱网站建设的基本规范有什么
  • 唯一做魅惑的网站怎么上网站做简易注销的步骤
  • 网站的导航栏怎么做自适应h5网站模板
  • 织梦网站logo站酷app
  • 说明网站建设与网站运营的区别南昌建网站单位
  • 科网站建设杭州门户网站开发
  • wordpress栏目首页企业seo如何优化
  • 做冻品海鲜比较大的网站有哪些化妆品营销型网站模板
  • 都匀住房和城乡建设局网站视频软件app
  • 网站建设用户需求曲阳有没有做网站里
  • 免费的个人主页网站做网站的销售
  • 团购网站建设流程杭州网站建设官网蓝韵网络
  • 做个网站要花多少钱福州seo视频
  • 做网站会后期维护吗建网站的网站有哪些
  • 国外的一个大学生做的匿名社交网站深圳seo优化推广业务员
  • 营销型网站建设的价格珠海网站建设网络推广
  • 如何设置标签wordpress江苏网站seo设计
  • 省住房城乡建设厅网站广州现在可以正常出入吗
  • 网站安全漏洞扫描工具自己做网站如何盈利
  • 花溪村镇建设银行网站网站怎样做的有吸引力
  • 杭州网站设计我选柚v米科技搭建之星
  • 美橙网站建设学习教程哪些方法可以建设网站
  • 网站建设 李奥贝纳电子商务行业发展现状
  • 佛山住房和城乡建设部网站官网中国十大热门网站排名
  • 一个网站如何做推广方案seo推广培训学费
  • 怎么做网站平台梦想网站用户体验是什么
  • 如何查看一个网站是不是用h5做的网站的费用
  • 网站建设技巧讠金手指排名26wordpress相同的cms