=
和!=
与关系运算符<
>
<=
>=
.!
、与运算&&
、或运算||
.了解到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 |