1. 程式人生 > >20172327 2017-2018-2 《程序設計與數據結構》第三周學習總結

20172327 2017-2018-2 《程序設計與數據結構》第三周學習總結

tps 序列 計算 lar 類庫 下使用 理解 返回 發現

20172327 2017-2018-2 《程序設計與數據結構》第三周學習總結

教材學習內容總結

  • 討論對象的創建和使用對象引用變量。
  • 探索String類提供的服務。
  • 描述如何組織成Java標準類庫包。
  • 探索隨機和數學課提供的服務。
  • 討論如何使用NumberFormat和DecimalFormat類格式輸出。
  • 介紹枚舉類型。

教材學習中的問題和解決問題

  • 暫無

代碼學習中的問題和解決過程

  • 問題1:在做項目pp0301時,出現了下面這中情況
    技術分享圖片

  • 問題1解決方案:通過仔細的分析,我發現代碼是對的,主要是數據輸入時出現了錯誤,這裏的姓至少要輸入5位,而我在輸入名字時,是按我的名字輸的,所以只有兩位,所以導致輸出不了數據。
  • 問題2:在做項目pp0302時,出現下面這個問題
    技術分享圖片

-0 問題2解決方案:經過和前面例題的對比,我發現Math._____之前要用括號將數據類型輸入進去,就像(int)(double)等

上周考試錯題總結

  • 問題1:Consider the following statement:
    System.out.println("1 big bad wolf\t8 the 3 little pigs\n4 dinner\r2night");
    This statement will output ________ lines of text (思考下面的語句,該語句將輸出___行文本)
  • 問題1分析:\t轉義序列插入一個選項卡,但將光標放在同一行。\n的轉義序列導致產生一個新行,以便“4晚餐”在下一行輸出。轉義序列\r使回車返回(也就是說,光標移回到左邊緣),但是因為它沒有開始新的行,“2night”輸出超過“4 dinn”,導致第二行看起來像“2nighter”。
  • 問題2:The word println is a(n) (單詞println是一個)
    A .method (方法)
    B .reserved word (保留字)
    C .variable (變量)
    D .class (類)
    E .String (字符串)
  • 問題2分析:println這個詞作為消息傳遞給系統。輸出對象,所以println是一個方法。
  • 問題3:Of the following types, which one cannot store a numeric value? (在下列數據類型中,哪一個不能存儲一個數值型數據?)
    A .int
    B .byte
    C .float
    D .char
    E .all of these can store numeric values (以上所有類型都可以存儲數值型數據)
  • 問題3分析:int和byte用於存儲整數(整數)和浮點數,用於存儲一個實數或浮點值(帶小數點的值)。字符存儲一個字符,包括字母、標點和數字。然而,存儲數字“5”與存儲數字5不一樣。
  • 問題4: What value will z have if we execute the following assignment statement? float z = 5 / 10; (如果我們執行下面的賦值語句,得到的z將會是什麽值?)
    A . z will equal 0.0 (z將等於0.0)
    B . z will equal 0.5 (z將等於0.5)
    C . z will equal 5.0 (z將等於5.0)
    D . z will equal 0.05 (z將等於0.05)
    E . none of the above, a run-time error arises because z is a float and 5 / 10 is an int (以上都不對,因為z是float類型,5 / 10是int類型,所以會發生運行時錯誤)
  • 問題4分析:因為5和10是整型變量,所以進行除法運算時就會按照整形變量即int型變量進行計算,然後再進行賦值型提升轉換,變成0.0.故選擇B.
  • 問題5:If x is an int and y is a float, all of the following are legal except which assignment statement? (如果x是一個int類型的數,y是一個float類型的數,下面所有賦值語句中哪個不合法?)
    A . y = x;
    B . x = y;
    C . y = (float) x;
    D . x = (int) y;
    E . all of the above are legal (以上全部合法)
  • 問題5分析:因為x是int,不能只是一個浮點數,除非浮動是扮演一個int。沒有明確在b的賦值語句,沒有必要因為一個浮動(y)可以接受一個int值(x),C和D,明確投存在法律。
  • 問題6:Which of the following is true regarding the mod operator, %? (關於求余運算符%,下面哪項是正確的?)
    A .It can only be performed on int values and its result is a double (它只能執行int類型的數值,其結果是double類型的數)
    B .It can only be performed on int values and its result is an int (它只能執行int類型的數值,其結果也是int類型的數)
    C .It can only be performed on float or double values and its result is an int (它只能執行float或者double類型的數值,其結果是int類型的數)
    D .It can only be performed on float or double values and its result is a double (它只能執行float或者double類型的數值,其結果是double類型的數)
    E .It can be performed on any numeric values, and the result always is numeric (它可以執行任何類型的數值,其結果始終是數值)
  • 問題6分析:Mod,或modulo,返回由一個分區產生的剩余部分。
    其余的總是數值型的。
    盡管通常使用整數值,但%運算符可用於所有類型的數值數據。
  • 問題7:What value will z have if we execute the following assignment statement?
    int z = 50 / 10.00; (如果我們執行下面的賦值語句,z將得到什麽值?)
    A .5
    B .5.0
    C .50
    D .10
    E .none of the above, a run-time error arises because z is an int and 50 / 10.00 is not (以上皆錯,因z是一個整型數而50 / 10.00不是,會產生運行時錯誤)
  • 問題7分析:因為10.00不是int,分裂產生一個雙精度值不能存儲在int z。為此,劃分的結果必須扮演一個int之前存儲在z,或價值10.00之前必須先扮演一個int劃分。
  • 問題8: Java is a strongly typed language. What is meant by "strongly typed"? (Java是一種強類型語言。“強類型”指的是什麽?)
    A . Every variable must have an associated type before you can use it (在使用變量之前,每個變量一定都有一個與之關聯的類型)
    B . Variables can be used without declaring their type (變量可以在不聲明其類型的情況下使用)
    C . Every variable has a single type associated with it throughout its existence in the program, and the variable can only store values of that type (在程序中,每個變量都有一個與之關聯的類型,而變量只能存儲該類型的值)
    D . Variables are allowed to change type during their existence in the program as long as the value it currently stores is of the type it is currently declared to be (變量存在於程序中時允許改變類型,只要它當前存儲的值是當前聲明的類型)
    E . Variables are allowed to change types during their existence in the program but only if the change is to a narrower type (變量存在於程序中時允許改變類型,但只能縮窄轉換)
  • 問題8分析:其實錯了這道題後我還是沒有理解,看到解析。 The reason that strong typing is important is it guarantees that a program that was successfully compiled will not have run-time errors associated with the misuse of types for the variables declared.我姑且翻譯一下:強類型很重要的原因是它不會誤用已經聲明了的類型的變量,保證了程序正常編譯而不會運行出錯。(在程序中,每個變量都有一個與之關聯的類型,而變量只能存儲該類型的值),B答案比較合理。
  • 問題9:A variable of type boolean will store either a 0 or a 1. (Boolean類型的變量將被存儲為0或1)
    A .true
    B .false
    問題9分析:布爾變量只能存儲兩個值中的一個,但這些值是保留字true和false。
    在C語言中,c++和c#布爾值被實現為只存儲0或1的int變量,但是在Java中,語言的作者選擇了真實和錯誤的布爾文字,因為這被認為是語義上更容易理解的(而且更安全)。

    [代碼托管](https://gitee.com/CS-IMIS-23/20172327mrf)

    技術分享圖片

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

進入第三周,有點難,程序的樣子和上一周有所改變,但要打的代碼更多了,發現時間有點不夠用,感覺這一周學的狀態並不好,所以下一周會花更多的時間在Java的學習中。

學習進度條

代碼行數(新增/累積) 博客量(新增/累積) 學習時間(新增/累積) 重要成長
目標 5000行 30篇 400小時
第一周 95/95 1/1 18/18
第二周 515/620 1/2 22/40
第三周 290/910 1/3 20/60

嘗試一下記錄「計劃學習時間」和「實際學習時間」,到期末看看能不能改進自己的計劃能力。這個工作學習中很重要,也很有用。
耗時估計的公式:Y=X+X/N ,Y=X-X/N,訓練次數多了,X、Y就接近了。

參考:軟件工程軟件的估計為什麽這麽難,軟件工程 估計方法

  • 計劃學習時間:25小時

  • 實際學習時間:22小時

  • 改進情況:沒有

(有空多看看現代軟件工程 課件
軟件工程師能力自我評價表)

參考資料

  • 《Java程序設計與數據結構教程(第二版)》

  • 《Java程序設計與數據結構教程(第二版)》學習指導
  • ...

20172327 2017-2018-2 《程序設計與數據結構》第三周學習總結