zoukankan      html  css  js  c++  java
  • 20172324 2017-2018-2 《程序设计与数据结构》第五周学习总结

    20172324《Java程序设计》第五周学习总结

    教材学习内容总结

    • 一个等号代表赋值,两个等号表示是否相等
    • if语句可以使程序选择是否执行某一条语句;if-else语句可以使程序在某个条件表达式的值为true的时候执行一段代码,其值为false的时候执行另外一段代码。switch语句将一个指定的字符或整型值分别与若干个case子句中的值进行匹配。
    • break语句常用来退出switch语句中的各个case子句。
    • while语句执行相同的语句,直到它的条件为false。do循环的循环体至少执行一次,for语句通常用于已知循环执行次数的情况。
    • 数据比较有相等性运算符和关系运算符、逻辑运算符;字符比较有compareTo和equals。

    教材学习中的问题和解决过程

    • 问题1:不同类型的值可以相互比较吗,比如int a;String b;if(a==b)
    • 问题1解决方案:这样会提示不可以比较,数值型和String类型的比较只能将数值型加上“”进行转化才可以让一个数值和一个字符串相等。
    • 问题2: switch要是没有break语句会怎样?
    • 问题2解决方案: 试验了一下结果就是每一句都输出了。

    代码调试中的问题和解决过程

    • 问题1:在做pp5.1的时候因为还没有看后面的第六章,所以想着用while的循环语句,但是这样输出的话有语法错误。
    • 问题1解决方案:在看完第六章之后就知道自己的问题了,在书上的例子中,while语句的括号里是一个表达式,类似于while(total>max)这种。但是我编的这个程序中,除了有一个表达式外,还有赋值和计算,所以就需要用for类型。在for的循环控制头中,申明的分别是(for初始化;表达式;for更新;)因为i变量是在for循环控制头中声明的,只存在于循环体内,循环控制变量在循环控制头中创建、检查和修改。
    • 问题2: 计算闰年时整除的表示方法。
    • 问题2解决方案: 我最开始想的是定义一个整型变量B,只要年份/4计算出来=B,那这个数就是一个整数,可是运行的时候就发现有错了,因为没有定义整型变量B的值。后来我就想整除四不就是除出来等于0嘛o_o ….结果就是不管如何输入最后输出的结果都是false,最后百度了一下才想起来原来还有除余%这个运算符。而且编的时候可以将三个条件连在一起A % 4 == 0 && A % 100 != 0 || A % 400 == 0就不需要(A % 4 == 0 && A % 100 != 0 )|| (A % 100 == 0&&A % 400 == 0)
    • 问题3:在编写石头剪刀布那个的时候,不知道怎么看胜负结果。最开始我想的是用字符串的长度来当作判断标准,然后用了这样的方法但是每次run出来的都是win:1 loose:2 draw:3然后我想应该是if-else的用法不正确,所以我就改成了这种,可是run出来的却始终是win:0 loose:0 draw:1
    • 问题3解决方案:我在之前已经给剪刀石头布分别赋了值,但是到后面就忘记赋值的目的是什么了...最后就将判断的那一块改成了列式计算,用用户输入的手势的赋值与电脑的赋值比较得出比较。
    • 问题4:输出的结果不是“HEADS=0,TAILS=100”就是“HEADS=100,TAILS=0”
    • 问题4解决方案:myCoin.filp这一步应该放在循环体类和循环体一起运算,而不是放在外面,这样的话不管条件是什么都会不停的循环循环体外的操作了,这样不好不好。

    代码托管

    (statistics.sh脚本的运行结果截图)

    上周考试错题总结

    1. Interface classes cannot be extended but classes that implement interfaces can be extended.
      A . true
      B . false
      都可以继承
    2. In order to preserve encapsulation of an object, we would do all of the following except for which one? :
      A . Make the instance data private
      B . Define the methods in the class to access and manipulate the instance data
      C . Make the methods of the class public
      D . Make the class final
      E . All of the above preserve encapsulation
      final是用来申明常量的
    3. What happens if you declare a class constructor to have a void return type?
      A . You'll likely receive a syntax error
      B . The program will compile with a warning, but you'll get a runtime error
      C . There's nothing wrong with declaring a constructor to be void
      D . The class' default constructor will be used instead of the one you're declaring
      E . None of the above
      加void类型并没有语法错误,只是不是构造函数而是一个普通的函数了,但是每一个函数里都有构造函数,如果自己加了void类型后也只会是出现一个空的构造函数而非产生语法错误。
    4. Inheritance through an extended (derived) class supports which of the following concepts? :
      A . interfaces
      B . modulary
      C . information hiding
      D. code reuse
      E . correctness
      ‎通过扩展类并从中继承, 新类不必重新实现任何继承的方法或实例数据, 从而节省了程序员的精力。因此, 代码重用是通过将他人的代码扩展为您的需要而重新使用其功能的能力。‎
    5. During program development, software requirements specify :
      A . how the program will accomplish the task
      B . what the task is that the program must perform
      C . how to divide the task into subtasks
      D . how to test the program when it is done
      E . all of the above
      软件需求指定了程序必须完成的功能,指明了程序应当执行的任务。
    6. The goal of testing is to :
      A . ensure that the software has no errors
      B . find syntax errors
      C . find logical and run-time errors
      D . evaluate how well the software meets the original requirements
      E . give out-of-work programmers something to do
      书上的原画!!!
    7. Static methods cannot :
      A . reference instance data
      B . reference non-static instance data
      C . reference other objects
      D . invoke other static methods
      E . invoke non-static methods
      静态方法是类本身的一部分, 而不是实例化对象的方法, 因此静态方法在类的所有实例化对象之间共享。由于静态方法是共享的, 因此它无法访问非静态实例数据, 因为所有非静态实例数据都特定于实例化对象。
    8. Which of the following reserved words in Java is used to create an instance of a class?
      A . class
      B . public
      C . public or private, either could be used
      D . import
      E . new
      ‎保留字 "new" 用于实例化对象, 即创建类的实例。新语句后面跟着类的名称。这将调用类的构造函数。例子: 汽车 x = 新的汽车 ();将创建一个新的汽车实例, 并设置变量 x。‎
    9. What happens if you declare a class constructor to have a void return type?
      A . You'll likely receive a syntax error
      B . The program will compile with a warning, but you'll get a runtime error
      C . There's nothing wrong with declaring a constructor to be void
      D . The class' default constructor will be used instead of the one you're declaring
      E . None of the above
    10. Formal parameters are those that appear in the method call and actual parameters are those that appear in the method header.
      A . true
      B . false
      问题有两个定义颠倒了。形式参数是出现在方法头中的形参, 实际参数是方法调用中的参数 (传递给方法)。
    11. All objects implement Comparable.
      A . true
      B . false
      可比较是一个接口, 并且类必须定义 compareTo 方法并且明确地陈述它实现可比较被认为是可比较的实施。大多数类不实现可比性。

    其他(感悟、思考等,可选)

    学习进度条

    代码行数(新增积) 博客量(新增积) 学习时间(新增积) 重要成长
    目标 5000行 30篇 400小时
    第一周 200/200 1/2 20/20
    第二周 329/500 2/4 18/38
    第三周 619/1000 3/7 22/60
    第四周 817/1734 4/7 38/60
    第五周 674/2408 5/7 38/60

    参考资料

  • 相关阅读:
    Unity shader 代码高亮+提示
    PTA --- L2-003 月饼
    PTA --- L2-002 链表去重
    计蒜客 —— 字符串p型编码
    计蒜客 —— 最好的草
    最近忙科研立项 & 对博客的优化
    计蒜客 —— 删除单词后缀
    Tensorflow 保存模型 & 在java中调用
    Tensorflow 用训练好的模型预测
    Tensorflow 保存和载入训练过程
  • 原文地址:https://www.cnblogs.com/amberR/p/8783199.html
Copyright © 2011-2022 走看看