=
和!=
與關係運算符<
>
<=
>=
.!
、與運算&&
、或運算||
.瞭解到switch語句。html
格式:java
switch(idChar)//在下列的caseA、B選擇一條語句並輸出。 { case 'A'://這是冒號、不是分號! aCount=aCount+1; break; //執行break語句後退出! case 'B': bCount=bCount+1; break; default: System.out.println("沒有能與idChar相匹配時,執行的語句」); }
學會了與if-else類似的條件運算符。git
條件運算符格式:編程
輸出兩個數中較大的那個數: int larger =(num1>num2) num1:num2;//num1與num2之間是:不是;
對do 和 for 語句。對while、do、for循環有了必定的認識。設計模式
1.do語句
格式:markdowndo { 計算的條件 } while (條件判斷);//while循環後面沒;此種語句計算的條件至少執行一次!數據結構
for語句:
格式:appfor (初始化部分;計算條件部分;遞增)//增量部分在每次循環完成後執行而且初始化部分只執行一次。 { (執行的語句)//判斷爲真時 }3.while,do,for循環的區別在後面說。ide
問題1解決方案:函數
算術運算符最高 關係運算符次之 邏輯運算符最低(!的優先級最高) 例如:9>3+4&&7先算3+4 再判斷9是否是大於7,再&&
問題3解決方案:
我如今的理解是:浮點值(double)用二進制表示是64位,經計算大約能表示小數點後15位左右。所以,有些浮點數是不能精確地被double表示的!
可是,若是想比較兩個數值a和b的相等性,咱們能夠用
`Math.abs(a-b)<某個精確值`
name1.equals(name2)
name1==name2
問題4解決方案:
首先呢,name1和name2都是String類型的數據。而且在方法二中,這種表達是沒有錯誤的。可是,方法一是比較兩個字符串中的每一個字符是否徹底相等,若是相同這輸出true,反之false.在方法二中,
==
實際是判斷兩個引用變量是否引用同一個字符串對象。(也就是是否互爲別名,通俗地說就是地址是否相同
問題5解決方案:
經過課本學習和百度搜索獲得如下答案:
迭代器是一種設計模式,它是一個對象,它能夠遍歷並選擇序列中的對象,而開發人員不須要了解該序列的底層結構。迭代器一般被稱爲「輕量級」對象,由於建立它的代價小。
- 使用方法iterator()要求容器返回一個Iterator。第一次調用Iterator的next()方法時,它返回序列的第一個元素。注意:iterator()方法是java.lang.Iterable接口,被Collection繼承。
- 使用next()得到序列中的下一個元素。
- 使用hasNext()檢查序列中是否還有元素.
- 使用remove()將迭代器新返回的元素刪除。
迭代器應用: ArrayList<數據類型> l = new ArrayList(); l.add("aa"); l.add("bb"); l.add("cc"); for (Iterator iter = l.iterator(); iter.hasNext();) { String str = (String)iter.next(); System.out.println(str); }
問題7解決方案:
1.while(循環條件) {命令} while的命令不必定要執行//次數多是零次 2.do {命令}//必須執行一次 while(循環條件) 無論while的循環條件如何好比(0>5),命令都會執行一次 3.for(初條件;末條件;循環方式) {命令} 例要輸出天然數1到5能夠是 for(int x=1;x<=5;x++) cout<<x<<endl;
問題2解決方案:經過問學長才知道出現這種狀況的緣由是:沒有注意到nextInt()方法與nextLine()的區別。
nextInt()讀取一個鍵盤獲取的數字以後焦點並不會移動到下一行,這時候若是下面語句中跟了一句nextLine()的話就讀不到輸入的內容了。由於nextLine()是遇到換行符結束讀取,nextInt()讀取的內容尚未換行,因此緊跟着nextInt()的nextLine()就只是讀取到了最後的換行符。因此並無接收到在上述程序中的y/n.
git add .
以前已經輸入了這個命令。這個問題的解決方案是直接輸入命令git push
.問題4解決方案:
對於這個問題我認爲的解決方案可能有兩種:
這兩種的公共點是運用ArrayList類構建石頭、剪刀、布三個對象。而後在條件的判斷上可能有不一樣。
共同點是:創建ArrayList類後讓把石頭剪刀布三個對象的索引分別爲一、二、3~(索引0能夠任意取一個對象,反正咱們不會使用它)~,以後咱們能夠判斷用戶與電腦選擇的選項是否相同,相同則爲平局。
不一樣點:利用相鄰的兩個對象必定有勝負,好比1(石頭)>2(剪刀)、2(剪刀)>3(布)
if (date1==date2-1)
{System.out.println("Did you lose!\n Your answer: "+band.get(date2)+"\nOpponent's answer: "+band.get(date1));
count1++;//電腦贏的次數
}
if (date2==date1-1)
{
System.out.println("You win it!\n Your answer: "+band.get(date2)+"\nOpponent's answer: "+band.get(date1));
count2++;//用戶贏得次數
}
if(date1==1&&date2==3)
{
System.out.println("You win it!\n Your answer: "+band.get(date2)+"\nOpponent's answer: "+band.get(date1));
count2++;//用戶贏得次數
}
if(date1==3&&date2==1)
{
System.out.println("Did you lose!\n Your answer: "+band.get(date2)+"\nOpponent's answer: "+band.get(date1));
count1++;//電腦贏的次數另外一個就是:規定好石頭>剪刀、剪刀>布、布>石頭,這種方法除了平局還有六種狀況須要處理,較上者稍微麻煩一些。
()
()
錯題1:
The relationship between a class and an object is best described as
A . classes are instances of objects
B . objects are instances of classes
C . objects and classes are the same thing
D . classes are programs while objects are variables
E . objects are the instance data of classes
正確答案:B 個人答案:E
如今理解:類包含示例數據和方法,對象須要類將它們實例化。
-錯題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
錯誤緣由:看到C中有一個public就覺得它不能保持封裝的穩定性,其實,public方法是爲了能在類的外面使用到這些方法,因此用public。
-錯題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 can not 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 int, double, float or String method
正確答案: B 個人答案:C
如今的理解:一個類的方法構建中必須有一個返回語句,如過不返回,須要在聲明返回值類型中用void聲明。
錯題4:
Consider a sequence of method invocations as follows: main calls m1, m1 calls m2, m2 calls m3 and then m2 calls m4, m3 calls m5. If m4 has just terminated, what method will resume execution?
A . m1
B . m2
C . m3
D . m5
E . main
正確答案:B 個人答案:C
正確理解:當一個方法中止時,控制會使用調用該方法的方法恢復。
錯題5:
Instance data for a Java class
A . are limited to primitive types (e.g., int, float, char)
B . are limited to Strings
C . are limited to objects(e.g., Strings, classes defined by other programmers)
D . may be primitive types or objects, but objects must be defined to be private
E . may be primitive types or objects
正確答案:E 個人答案:C
理解狀況: 實例數據是組成該類的實體,多是任何可用的類型,不管是原始的仍是對象的,多是公有的仍是私有的。經過使用對象做爲實例數據,它容許將類構建在其餘類之上。這種關係中,類擁有其餘類的實例數據,稱爲has-a關係。
錯題6:
Consider a Rational class designed to represent rational numbers as a pair of int's, along with methods reduce (to reduce the rational to simplest form), gcd (to find the greatest common divisor of two int's), as well as methods for addition, subtraction, multiplication, and division. Why should the reduce and gcd 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 Rational's instance data
E . Because it is a typo and they should be declared as public
正確答案:B 個人答案:C
理解狀況:被聲明爲私有的類的全部條目只能被該類中的實體訪問,無論它們是實例數據仍是方法。在這種狀況下,因爲這兩種方法只從Rational的其餘方法(包括構造函數)調用,因此它們被聲明爲私有,以促進信息隱藏在更大的程度。
錯題7:
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
正確答案:D 個人答案:C
理解狀況:構造一個類會包含構造方法,當沒有構造方法時,系統自動生成一個爲空的構造方法。所以在構造方法中加入Void會使其變成普通的方法,將構造方法變成爲空。
錯題8:
All Java classes must contain a main method which is the first method executed when the Java class is called upon.
A . true
B . false
正確答案 B 個人答案:A
理解狀況:只有驅動程序須要一個主方法。驅動程序是在任何Java程序中首先執行的(除了applet),可是它能夠根據須要調用其餘類,而這些其餘類不須要主要方法。
錯題9:
Which of the following interfaces would be used to implement a class that represents a group (or collection) of objects?
A . Iterator
B . Speaker
C . Comparable
D . MouseListener
E . KeyListener
正確答案:A 個人答案 E
理解狀況:迭代器是一個抽象類,容許用戶經過使用此處定義的特性來擴展實現Iterator的給定類。這些特性包括可以存儲一組對象並經過它們進行迭代(步驟)。
這兩章相對來講比較簡單,可是仍有許多的細節須要注意好比while語句使用時判斷語句的後面不須要分號,而在do-whiled的後面須要一個分號等。
代碼行數(新增/累積) | 博客量(新增/累積) | 學習時間(新增/累積) | 重要成長 | |
---|---|---|---|---|
目標 | 5000行 | 30篇 | 400小時 | |
第一週 | 075/200 | 1/1 | 05/05 | |
第二週 | 560/500 | 1/2 | 13/18 | |
第三週 | 972/1000 | 2/4 | 21/39 | |
第四周 | 694/1666 | 1/5 | 21/60 | |
第五週 | 1544/3095 | 1/6 | 30/90 |