第02章+JAVA语言基础.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
* 步骤: 1)画流程图 2) 编写程序 * * 演示时注意讲解如果else if的顺序被调整,会怎样 * * * 演示时在某些case中添加break看一看效果 * * * * * * * * * * * * * 1)讲语法,有三个表达式,分别用来做什么 2)讲执行顺序,对应着引例讲 3)讲代码规范 * * * * * * * * 可以演示给常量赋值报错 * * * * * * * * * * * * * * * 整型、实型和字符型数据需要进行混合运算时,首先需要把不同类型的数据转化为同一类型,然后才能进行运算。转换时,系统将按照数据类型的表示范围由小到大的转换原则自动进行。 数据类型的表示范围由小到大的顺序依次为: * * 演示出错信息及改后的结果,讲解当强制转换时,精度有损失 * * 表达式就是运算符(如加号、减号)与操作数(如b,3等)的组合。 * * * * * * * * * * 数组赋值 方法1: 边声明边赋值 方法2:动态地从键盘录入信息并赋值 解决 int[ ] score = {89, 79, 76}; Scanner input = new Scanner(System.in); for(int i = 0; i 30; i ++){ score[i] = input.nextInt(); } int[ ] score = new int[ ]{89, 79, 76}; 使用数组求平均值-1 60 80 90 70 85 int [ ] score = {60, 80, 90, 70, 85}; double avg; avg = (score[0] + score[1] + score[2] + score[3] + score[4])/5; int [ ] score = {60, 80, 90, 70, 85}; int sum = 0; double avg; for(int index = 0; index score.length; index++){ sum = sum + score[index]; } avg = sum / score.length; 成绩单 访问数组成员:使用“标识符[下标]” 访问成员 数组的length属性 对数据进行处理:计算5位学生的平均分 4 使用数组求平均值-2 回顾问题1: 令狐冲的班里有30位学生,使用动态录入并赋值的方式计算平均分 public class HelloAccp2{ public static void main(String[ ] args){ int[ ] score = new int[ ]; score[0] = 89; score[1] = 63; System.out.println(score[0]); } } 常见错误-1 编译出错,没有写明数组的大小 public class HelloAccp3{ public static void main(String[ ] args){ int[ ] score = new int[2]; score[0] = 89; score[1] = 63; score[2] = 45; System.out.println(score[2]); } } 常见错误-2 编译出错,数组越界 常见错误-3 public static void main(String[ ] args){ int[ ] score = new int[5]; score = {60, 80, 90, 70, 85}; int[ ] score2; score2 = {60, 80, 90, 70, 85}; } 编译出错,创建数组并赋值的方式必须在一条语句中完成 public class Hello{ public static void main(String[ ] args){ int[ ] score = new int[3]; score[0] = 89; System.out.println(score[1]); } } int数组元素缺省值为0 0 0 0 0 89 0 0 0 1 2 输出结果 小结2 使用数组的步骤是什么? 有一个数列:8,4

文档评论(0)

22255990 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档