2017-2018-2學期 20172324《Java程式設計》第六周學習總結

來源:互聯網
上載者:User

標籤:程式設計語言   markdown   default   OLE   上傳   variables   比較   另一個   數學   

20172324《Java程式設計》第六周學習總結教材學習內容總結
  • 如何建立數組以及int[] X與int X[]的區別(編譯時間是沒有差別的,只是前者與其他類型的聲明方式有一致性)
  • 每一個java數組都是一個迭代器。
  • 數組是作為參數傳遞給一個方法的,實際上傳遞的是原始數組引用的副本。
  • 對象數組(基礎資料型別 (Elementary Data Type)+對象)
  • 二維數組中前一個索引值代表行,另一個索引值代表列。
  • 可變長度參數用...

    教材學習中的問題和解決過程
  • 問題1: Family代碼中String...name中的...是什麼意思。
  • 問題1解決方案:這是jdk1.5的新特性:變長變數。也就是說可以傳入任意多個參數。比用資料更靈活一些,不會出現一些數組越界等的異常。 如:
    getType(String...values);調用時,可以getType("a","b","c")等,參數個數沒有限制,類型是前面規定的String類型。(嘻嘻原來書上就有的被我看岔了)

  • 問題2:pp8.3我有點不懂。就是upper[current-‘A‘]++那裡,到底是什麼加了1?
  • 問題2解決方案: 我只能一步步寫注釋。

for(int ch=0;ch<line.length();ch++)        {            current = line.charAt(ch);//定義current是輸入的字串從索引0開始的字元            if(current>=‘A‘&&current<=‘Z‘)//這裡和Unicode有關,如果這個大寫字母在A`Z之間                upper[current-‘A‘]++;//那麼current-‘A‘就代表索引處那個特定的字元,索引處的值加1(最開始是0,因為沒有出現過)            else                if(current>=‘a‘&&current<=‘z‘)//同上嘛,就是小寫而已。                    lower[current-‘a‘]++;                else                    other++;        }        
代碼調試中的問題和解決過程
  • 問題1:pp8.1中,我開始是想定義一個數組,把我想輸入的值按大小放進索引裡,沒有出現的值就用0補齊,並且如果出現相同的值,那個索引值裡數位個數就增加1,後來發現,一個索引裡只能放一個值,不存在相同數字放在同一個索引下的情況。導致我不管輸入什麼值輸出的個數全都是0。
  • 問題1解決方案:==利用二維數組==。第一步先建立兩個都包含0~50這51個數的數組,一個用來放你輸入的數,一個用來計算前一個數組中不同索引裡相同數的值的個數。第二部用Scanner方法輸入你想輸入的數,將它們一個個放在數組A裡。第三步,計算你輸入的數值個數,並且定義一個初始值為0,又在輸入數值個數範圍內的數,相同的值就在數組B中對應位置增加出現次數。第四步輸出從0到50這51個數且你輸入的數出現的頻率。
  • 問題2: pp8.5,如何表示繼續輸入一個數。
  • 問題2解決方案:在書上第五章提到過,String一個字串,然後定義為y,利用字串是否相等,即equalsIgnoreCase()這個比較,決定是否繼續輸入。
  • 問題3:繼續上一個問題...我不停在“是否繼續輸入”這個問題上迴圈,還到不了輸入資料這。

  • 問題3解決方案:編寫的時候直接向第五章一樣的String了一個str,還String了一個定義為“y”的another值,但其實在這章裡不需要str來輸入迴文。所以定義一個another就可以了,否則的話就會像我這樣了....其實我還是不太懂,我再去看看書。

String another = "y";//建立一個字串命令它表示為y    int[] list = new int[50];//可以放50個數的數組        //建立一個可以連續輸入數位迴圈        while(another.equalsIgnoreCase("y"))//哦~這裡的another要和下面輸入的another做比較        {            Scanner scan = new Scanner(System.in);            System.out.print("是否繼續輸入(y/n): ");            another = scan.nextLine();//就是這裡的            if (another.equalsIgnoreCase("y") )//another輸入為y就可以輸入資料,所以不需要多的字串。            {                System.out.print("Enter your number: ");                number = scan.nextInt();                list[i] = number;                i++;            }        }
  • 問題4:pp8.6是一個很大的問題,無解...

## 代碼託管

(statistics.sh指令碼的運行結果)

上周考試錯題總結
  1. The idea that program instructions execute in order (linearly) unless otherwise specified through a conditional statement is known as
    A . boolean execution
    B . conditional statements
    C . try and catch
    D . sequentiality
    ==E . flow of control==
    "控制流程" 描述指令執行的順序。它預設為線性 (或連續), 但通過使用諸如條件和迴圈等控制語句來改變。
  1. 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?
    A . if (x > 0) x++;
    else x--;
    ==B . if (x > 0) x++;
    else if (x < 0) x--;==
    C . if (x > 0) x++;
    if (x < 0) x--;
    else x = 0;
    D . if (x == 0) x = 0;
    else x++;
    x--;
    E . x++;
    x--;
    如果 x 為正數, 則在 x 為負 x 的情況下執行 x++, 否則, 不會發生任何情況, 或者 x 不受影響。在 A、C、D 和 E 中, 邏輯不正確。在 A, x-是做如果 x 是不積極的, 因此, 如果 x 是 0, x 成為-1, 這是錯誤的答案。在 C 中, 如果 x 為正數, 則執行 x++。在任一情況下, 將執行下一語句, 如果 x 不是負值, 則執行 else 子句將 x 設定為0。因此, 如果 x 是正數, 則在這組代碼之後變為0。如果 x 不是 0, 則在 D、x++ 和 x 中都執行。在 E 中, 此代碼不嘗試確定 x 是正數還是負數, 它只添加一個, 然後從 x 中減去 1, 使 x 相同。
  1. Assume that count is 0, total is 20 and max is 1. The following statement will do which of the following? if (count != 0 && total / count > max) max = total / count;
    ==A . The condition short circuits and the assignment statement is not executed==
    B . The condition short circuits and the assignment statement is executed without problem
    C . The condition does not short circuit causing a division by zero error
    D . The condition short circuits so that there is no division by zero error when evaluating the condition, but the assignment statement causes a division by zero error
    E . The condition will not compile because it uses improper syntax
    因為計數是 0, (計數! = 0) 是假的。因為 & & 條件的左手邊是假的, 所以條件是短路的, 所以右手邊是不計算的。因此, 避免了潛在的除法錯誤。由於條件為 false, 語句最大 = 總計/計數未執行, 再次避免潛在除法為零錯誤。
  1. 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
    ==E . all of the above==
    有關複選框的四個語句中的每一個都是 true。
  1. When comparing any primitive type of variable, == should always be used to test to see if two values are equal.
    A . true
    ==B . false==
    這對 int、短、位元組、長、char 和布爾值都是正確的, 但不能是雙變數或浮點函數。
  1. You might choose to use a switch statement instead of nested if-else statements if
    A . the variable being tested might equal one of several hundred int values
    ==B . the variable being tested might equal one of only a few int values==
    C . there are two or more int variables being tested, each of which could be one of several hundred values
    D . there are two or more int variables being tested, each of which could be one of only a few values
    E . none of the above, you would never choose to use a switch statement in place of nested if-else statements under any circumstance
    只有在測試單個變數並且它是整數類型 (在 Java 中為 int 或 char) 時, 才可以使用 switch 語句。
  1. If a switch statement is written that contains no break statements whatsoever,
    A . this is a syntax error and an appropriate error message will be generated
    B . each of the case clauses will be executed every time the switch statement is encountered
    C . this is equivalent to having the switch statement always take the default clause, if one is present
    D . this is not an error, but nothing within the switch statement ever will be executed
    ==E . none of the above==
    雖然寫這樣一個開關聲明是不尋常的, 它是完全合法的。切換語句執行的常規規則應用在計算切換運算式後執行的匹配 case 子句。隨後, 所有後續子句都按順序執行, 因為沒有中斷語句來終止交換器/案例執行。
  1. The statement if (x < 0) y = x; else y = 0; can be rewritten using a conditional operator as
    ==A . y = (x < 0) ? x : 0;==
    B . x = (x < 0) ? y : 0;
    C . (x < 0) ? y = x : y = 0;
    D . y = (x < 0);
    ==E . y = if (x < 0) x : 0;==
    看書看書看書看書看書看書
  1. How many times will the following loop iterate?
    int x = 10;
    do {
    System.out.println(x);
    x--;
    } while (x > 0);
    A . 0 times
    B . 1 times
    C . 9 times
    D . 10 times
    ==E . 11 times==
    沒話說….do迴圈一定會執行一次的,好好學數學,好好數。
  1. 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));
    ==A . it prints s out backwards==
    B . it prints s out forwards
    C . it prints s out backwards after skipping the last character
    D . it prints s out backwards but does not print the 0th character
    E . it yields a run-time error because there is no character at s.charAt(j-1) for j = 0
    變數 j 從字串的長度向下計數為 1, 每次列印出位置 j-1 的字元。長度為1的字元是第一個列印字元, 這是字串的最後一個字元。它繼續, 直到它達到 j = 1, 並列印出的字元在位置 j-1, 或第0字元, 所以它列印整個字串向後。
  1. In Java, it is possible to create an infinite loop out of while and do loops, but not for-loops.
    A .true
    B .false
    誠然, 雖然while和do迴圈可以是無限迴圈, 但for 迴圈可以是無限迴圈。在許多其他程式設計語言中, 這不是真的, for 迴圈有一個設定的開始和結束點, 但是 Java for 迴圈比大多數其他語言的 for 迴圈要靈活得多
結對及互評點評模板(why點評我!)
  • 部落格中值得學習的或問題

  • 介面排版很好看
  • 問題分析很詳細,有自己的思考
  • 對學習的總結很到位,提出和解決的問題也是很重點的知識點

  • 代碼中值得學習的或問題

  • 關鍵代碼注釋很詳細
  • 基於評分標準,我給本部落格打分:14 。得分情況如下:
  1. 正確使用Markdown文法(加1分)
  2. 模板中的要素齊全(加1分)
  3. 教材學習中的問題和解決過程, 加4分
  4. 代碼調試中的問題和解決過程, 加4分
  5. 本周有效代碼超過300分行,加2分
  6. 其他加分,加2分
  • 排版精美的加一分
  • 進度條中記錄學習時間與改進情況的加1分
本周結對學習情況
  • 結對同學學號21號
  • 結對學習內容

  • 一起討論學習了課後編程項目pp8.1和pp8.5,pp8.6我是真的不行了,希望你學會了來救救我。

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

我學得要死不活的時候,王志偉說很簡單。我感覺好悲傷,希望能夠打他一頓解心頭之狠。這個星期的感悟結束。

學習進度條
程式碼數(新增積) 部落格量(新增積) 學習時間(新增積) 重要成長
目標 5000行 30篇 400小時
第一周 200/200 2/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
第劉周 1136/2870 6/7 50/60
參考資料
  • Java.API線上文檔

2017-2018-2學期 20172324《Java程式設計》第六周學習總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.