zoukankan      html  css  js  c++  java
  • 《程序设计与数据结构》第六周学习总结

    学号 20172326 《程序设计与数据结构》第六周学习总结

    教材学习内容总结

    • 索引值由0开始,不注意时可能出现差一错误
    • double,int,float初始化数组后默认数组中每个对应索引值的 默认值为0 ,老师上课提到,不为零,为一组随机数。char与String对应为空。
    • 可以将数组中的数据作为变量输出。

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

    • 问题:例题8.3中获取索引的问题
    • 问题1解决方案:
      大致的模式可以理解,但是,程序是如何识别“a”是a呢?
      本段程序如下
    for (int ch = 0;ch<line.length();ch++)
          {   
             current = line.charAt(ch);
             if (current >= 'A'&& current <= 'Z')
               upper[current-'A']++;
             else 
               if (current >= 'a' && current <= 'z')
                  lower[current-'a']++;
               else 
                  other++;
          }   
    
    
    • 在不断理解上下文后发现,首先在char中,对应的不是理解中的字母,而是Unicode码,例如A是65,所以是减去A对应着减去其uincode码。从中可以锁定句中的字母的索引。而又已知的是数组默认值为0,所以,如果有相应字母,那么通过upper[]++来增加对应索引的内容。
      对应的,在输出时,有
    // Print the results
          System.out.println();
          for (int letter=0; letter < upper.length;letter++)
          {   
             System.out.print((char)(letter + 'A'));
             System.out.print(": " + upper[letter]);
             System.out.print("		" + (char)(letter + 'a'));
             System.out.print(":" + lower[letter]);
          }   
    
    
    • 继续利用Unicode码,从A开始,A为65,则对应的letter从0开始。可以轻易的将数字转化为字符。

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

    • 问题:PP8.1的编写 ,有以下问题:

    • 1是超出范围时退出的问题。当时想到了break语句,但是出现了许多问题。

    • 2是在寻找索引的问题,因为输入一个数字时无法确定其位置

    • 3是在开始时应当怎样输入,是用string还是char还是int型。

    • 问题解决方案:

    • 1其实不用选择,因为执行for与while语句时,如若没有满足条件,则自动退出循环。

    • 2在向学长请教后,加深了理解,申明一个数组后,只需要对号入座,例如输入5.那么,在num[]中,a=5,则有num[5]=0,再接着使用num[]a++,使得num[a]=1,即记录一次。

    • 3 用int型,结合循环后 即可

    • 其他

    • 输出时,怎样使其输出有规律,学长有精心的为我指出如下代码

    for (int i=0;i<num.length;i++)
          {   
             System.out.print(i+":"+num[i] +"	");
        
            if(i%5==0&&i!=0)
            System.out.println();
            }
    
    • 这里也蕴含着一定技巧当这行输出了五行时,自动换行。

    代码托管

    上周考试错题总结

    • 错题1

    The idea that program instructions execute in order (linearly) unless otherwise specified through a conditional statement is known as-flow of control

    • 原因,理解情况:
    • 在默认情况下,程序逐条执行命令,但是遇到判断、循环语句时,根据逻辑顺序进行执行
    • 错题2

    Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is negative but leave x alone if x is 0?-if (x > 0) x++;
    else if (x < 0) x--;

    • 原因,理解情况:
    • if (x > 0) x++;
      if (x < 0) x--;
      else x = 0;
    • 错选了c,如果时c,那么在执行第二条if语句时,会有正数为0的情况。
    • 错题3

    If x is an int where x = 1, what will x be after the following loop terminates?
    while (x < 100)
    x *= 2;--128

    • 原因,理解情况:
    • 当x为64时继续循环,结果为128,不符合循环,但此时x已经为128
    • 错题4

    Which of the following are true statements about check boxes?--

    • A . they may be checked or unchecked
    • B . radio buttons are a special kind of check boxes
    • C . they are Java components
    • D . you can control whether or not they will be visible
    • 原因,理解情况:

    • 第八题属于星号内容,查书可得

    • 错题5

    The statement if (x < 0) y = x; else y = 0; can be rewritten using a conditional operator as-- y = (x < 0) ? x : 0;

    • 原因,理解情况:
    • (x < 0) ? y = x : y = 0
    • 错选为顺序错误,第一处为赋值语句,?为判断,“:”为选择
    • 错题6

    Given the following code, where x = 0, what is the resulting value of x after the for-loop terminates?
    for (int i=0;i<5;i++)
    x += i;--10

    • 原因,理解情况:
    • i = 0,x = x + 0 = 0; i= 1 x = x + 1 = 1;
    • i = 2 x = x + 2 = 3; i = 3 x = x + 3 = 6;
    • i = 4 x = x + 4 = 10;
    • 错题7

    Given that s is a String, what does the following loop do?
    for (int j = s.length( ); j > 0; j--)
    System.out.print(s.charAt(j-1));-- it prints s out backwards

    • 原因,理解情况:
    • charAt()括号中为索引值,所以,注意其数字
    • 错题8

    Each case in a switch statement must terminate with a break statement--false

    • 原因,理解情况:
    • 最后一个case语句就可以不用
    • 错题9

    In Java, it is possible to create an infinite loop out of while and do loops, but not for-loops.

    • 原因,理解情况:
    • 任何语句都可以产生无限循环

    单词总结

    • iterate 迭代(循环) positive正

    学习进度条

    代码行数(新增/累积) 博客量(新增/累积) 学习时间(新增/累积) 重要成长
    目标 5000行 30篇 400小时
    第一周 110/200 1/1 20/20
    第二周 425/500 2/2 18/38
    第三周 900/1000 4/4 22/60
    第四周 1500/1300 5/5 30/90
    第五周 2715/3000 6/6 20/110
    第六周 3097/3500 7/7 20/130

    感想

    本周用三天时间学第八章感觉有些紧张,很多问题理解得不够到位,但在解决后很开心。

    点评过的同学博客和代码

    • 20172313

    • 博客中值得学习的或问题:

    • 排版用了css。

    • 图片截图可以结果和代码分开,会看着更舒服

    • 教材内容总结的很有意思,很用心。

    • 详略得当,问题发现的一针见血,很有针对性,可以看出写代码时,前后的流程十分规范。

    • 博客样式精美,给人以赏心悦目的体验。

    • 能够使自己和读者都能起到提升的作用。

    • 代码中值得学习的或问题:

    • 在往博客中打代码时,可以用``这个方式,会使代码变成规范的代码形式。

    • 博客链接

    参考资料

  • 相关阅读:
    速查快递
    浅谈C#中常见的委托<Func,Action,Predicate>(转)
    C#用扩展方法进行自动生成添加删除对象转换的功能
    sql字符串分组
    PowerDesigner连接SQL Server
    老程序员的下场(转)
    界面设计:一个像素之差产生的距离(转)
    程序员如何活得明白(转)
    真实死锁案例记录
    分享java常用技术教程:dubbo、zookeeper、ActiveMq、多线程、Redis、PowerDesigner等
  • 原文地址:https://www.cnblogs.com/326477465-a/p/8850351.html
Copyright © 2011-2022 走看看