1、條件語句
一、條件語句的內容:if語句、if-else語句和switch語句(此語句在第六章詳細介紹其功能);
二、if語句:由保留字if、緊隨其後的布爾表達式及一條或一組語句構成;
三、if-else語句:當咱們但願當某個條件表達式的值爲true時作的一件事情,爲false時作的另一件事情;php
2、循環語句
一、循環語句的內容:while語句、do語句和for語句 (該章主要講解while語句內容及其功能);
二、while語句:當條件符合時,接着作下面的語句;不符合時,退出循環;html
3、數據比較
一、數據比較所用的相關運算符:相等性運算符和關係運算符、邏輯運算符;
二、比較對象的不一樣所用的方法也不一樣:浮點數比較、字符比較;git
4、迭代器
一、迭代器對象的基本方法;
二、ArrayList類的用法;web
1、條件語句
一、switch語句內容: 其做用是進行判斷選擇;
二、條件運算符:與if-else類似但不相同,一般書寫爲:「?:」;express
2、循環語句
一、do語句:與while類似,可是它是先執行後判斷,至少會執行一次;
二、for語句:特別適用於循環執行前已經確切知道具體循環次數的狀況;編程
if(num1<num2) if(num1<num3) min = num1; else min = num3; else if (num2<num3) min = num2; else min = num3;
if(code == 'R') if(height <= 20) System.out.println("Situation Normal"); else System.out.println("Bravo!");
當時就有一點暈,可是按照邏輯分析,我認爲沒有錯誤,因此就按照上面兩種敲了做業,其中就出現了問題,當我在利用第二種代碼敲好個人做業pp5.3以後,編譯之後沒有錯,並且能夠正常輸出。
數據結構
在我以爲的確能夠這樣寫之後,我就按照這種方式編寫了個人pp5.7,可是問題就來了,出現了這個錯誤:app
當時真的瞬間就傻了,就回頭去檢查pp5.3,發現依舊能夠輸出,最後發現沒有加{},問題的根源就是pp5.7的時候須要加上「塊」,由於裏面不只僅只有「XX++」了,還要輸出,計算,問題的解決的依舊在書中也找到了:ide
else子句會和它前面最近的沒有匹配項的if語句相匹配。學習
因此,雖然有時候不須要一一對應,可是要記住,else必定要管夠,缺一不可。
結果
問題也就解決了。
while循環和do循環的主要不一樣之處在於什麼時候計算條件表達式的值。若是要讓循環體至少執行一次,do循環一般是更好的選擇。而對於while循環來講,若是表達式初始值爲fales,則循環體一次都不會執行。
當循環次數是肯定的貨是很容易計算時,一般使用for。
問題1:在編寫while練習題的時候,發生了一個所謂的無限循環,當時驚訝到我了,如圖:
問題1解決方法:
就是由於while花括號沒有放對位置,致使一直進行着死循環。
問題2:在編寫做業的時候,發現輸出的語句跳了一個:
檢查代碼:
問題2解決方案:
神奇的發現本身給while多打了一個「;」
特別尷尬...
問題3:
在編寫做業的時候,老是提示我輸入的數字超出範圍....
問題3解決方案:
分析了本身編寫程序的每一句話,發現了問題,在這裏:
我定義的num3結果是輸入字符串的字符個數,最後輸入「666」告訴我「666>3,不行!」,最後把那個長度改正了,問題也就解決了。
git出現了一次問題,刪除了不少代碼。
commit格式還在學習當中,掌握立刻修改。
錯題1:
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
正確答案: E 個人答案: C
緣由:我理解成了創造類,編寫類用哪個,而後就沒有理解,選擇錯誤。
錯題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
正確答案: D 個人答案: C
緣由:我作題有時候會忘記定義一個常量要用final,通常編程序的時候纔有意識去想。
錯題3:
If a method does not have a return statement, then
A. it will produce a syntax error when compiled
B. it must be a void method
C. it cannot be called from outside the class that defined the method
D. it must be defined to be a public method
E. it must be an in, double, float or String method
正確答案: B 個人答案: C
緣由:我認爲若是不能返回一個聲明,它就沒法在測試程序中輸出出來,我以爲它就不能被調用。
錯題4:
Consider a Rational class designed to represent rational numbers as a pair of nit’s, along with methods reduce (to reduce the rational to simplest form), god (to find the greatest common divisor of two nit’s), as well as methods for addition, subtraction, multiplication, and division. Why should the reduce and god methods be declared to be private.
A. Because they will never be used
B. Because they will only be called from methods inside of Rational
C. Because they will only be called from the constructor of Rational
D. Because they do not use any of Rationale’s instance data
E. Because it is a typo and they should be declared as public
正確答案: B 你的答案: C
緣由:我在學習本章的時候就出現了概念性的錯誤,我覺得方法是屬於構造方法的,實際上它們是並列的。
錯題5:
Consider a method defined with the header: public void foo (in a, in b). Which of the following method calls is legal?
A. foo (0, 0.1);
B. foo (0 / 1, 2 * 3);
C. foo (0);
D. foo ( );
E. foo (1 + 2, 3 * 0.1);
正確答案: B 你的答案: D
緣由:看到int,與(0/2)比較感受一個是整形變量,一個是浮點數,其實(0/2)=0嗎?(捫心自問)
錯題6:
Consider a method defined with the header: public void double foo (double x). Which of the following method calls is legal?
A. double foo (0);
B. double foo (0.555);
C. double foo (0.1 + 0.2);
D. double foo (0.1, 0.2);
E. all of the above are legal except for D
正確答案: E 你的答案: B
緣由:這道題,純屬眼瞎,看題的時候,沒有注意那個是逗號;
錯題7:
The expressions that are passed to a method in an invocation are called
A. actual parameters
B. formal parameters
C. formal arguments
D. formals
E. any of the above
正確答案: A 你的答案: B
緣由:典型的概念理解模糊,當時仍是不夠清楚形參和實參的具體概念。
錯題8:
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
正確答案: A 你的答案: D
緣由:這道題,老師從新講了,答案是D,我對啦!
錯題9:
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
正確答案: B 你的答案: A
緣由:出現了和上上一題同樣的錯誤。
錯題10:A method defined in a class can access the class' instance data without needing to pass them as parameters or declare them as local variables.
A. true
B. false
正確答案: A 你的答案: B
緣由:後來在書裏給我找到了這句話的原句,每次都發現看書不仔細。
錯題11:
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
正確答案: B 你的答案: E
緣由:當時很單純的覺得,這種題不該該全部都有嗎,最後發現這是一個坑。
錯題12:
Which of the following methods is a static method? The class in which the method is defined is given in parentheses following the method name.
A. equals (String)
B. to Uppercase (String)
C. sort (Math)
D. format (Decimal Format)
E. paint (Applet)
正確答案: C 你的答案: B
緣由:這道題忘記當時爲何選B,好像發現有一點看不懂,就隨便編了一道。
錯題13:
Inheritance through an extended (derived) class supports which of the following concepts?
A. interfaces
B. modular
C. information hiding
D. code reuse
E. correctness
正確答案: D 你的答案: A
緣由:原本選的D,查單詞的時候,點空白,點到了A,崩...
錯題14:
Interface classes cannot be extended but classes that implement interfaces can be extended.
A. true
B. false
正確答案: B 你的答案: A
緣由:我理解概念正好與其相反了,上次上課,老師已經將講過,糾正了本身的錯誤。
錯題15:
All objects implement Comparable.
A. true
B. false
正確答案: B 你的答案: A
緣由;對概念的理解不清楚。
錯題16:
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
正確答案: B 你的答案: A
緣由:同某一道題,如出一轍的。
代碼行數(新增/累積) | 博客量(新增/累積) | 學習時間(新增/累積) | |
---|---|---|---|
目標 | 5000行 | 30篇 | 400小時 |
第一週 | 156/156 | 1/1 | 15/15 |
第二週 | 217/371 | 1/2 | 20/35 |
第三週 | 233/604 | 2/4 | 20/55 |
第四周 | 1382/1986 | 1/5 | 35/90 |
第五週 | 146/2196 | 1/6 | 25/115 |