1.
______A_____ is attached to the class of the composing class to denote the aggregation relationship with the composed object.
A.An empty diamond
B.A solid diamond
C.An empty oval
D.A solid oval
答:空钻石运算符 (<>)附加到组合类的类,以表示与组合对象的聚合关系。
2.Assume StringBuilder strBuf is "ABCCEFC", after invoking ____E_____, strBuf contains "ABTTEFT".
A.strBuf.replace('C', 'T')
B.strBuf.replace("C", "T")
C.strBuf.replace("CC", "TT")
D.strBuf.replace('C', "TT")
E.strBuf.replace(2, 7, "TTEFT")
答:假设 StringBuilder strBuf 是 “ABCCEFC”,调用______后,strBuf 包含 “ABTTEFT”
strBuf.replace(strat: ,end: ,str: );
3.Assume StringBuilder strBuf is "ABCDEFG", after invoking _____B____, strBuf contains "ABCRRRRDEFG".
A.strBuf.insert(1, "RRRR")
B.strBuf.insert(2, "RRRR")
C.strBuf.insert(3, "RRRR")
D.strBuf.insert(4, "RRRR")
4.Assume StringBuilder strBuf is "ABCDEFG", after invoking ___C___, strBuf contains "AEFG".
A.strBuf.delete(0, 3)
B.strBuf.delete(1, 3)
C.strBuf.delete(1, 4)
D.strBuf.delete(2, 4)
答:将删除这个序列的一个子字符串中的字符,子字符串的开始在指定的start和延伸处的字符索引end - 1或结束的序列。
5.Which of the following is the correct statement to return a string from an array a of characters?______B______
A.toString(a)
B.new String(a)
C.convertToString(a)
D.String.toString(a)
答:以下哪项是从字符数组 a 返回字符串的正确语句
6.What is the output of the following code?___B____
- public class Test {
- public static void main(String[] args) {
- String s1 = new String("Welcome to Java!");
- String s2 = new String("Welcome to Java!");
-
- if (s1 == s2)
- System.out.println("s1 and s2 reference to the same String object");
- else
- System.out.println("s1 and s2 reference to different String objects");
- }
- }
A.s1 and s2 reference to the same String object
B.s1 and s2 reference to different String objects
7.What is the output of the following code?____A____
- public class Test {
- public static void main(String[] args) {
- String s1 = "Welcome to Java!";
- String s2 = "Welcome to Java!";
-
- if (s1 == s2)
- System.out.println("s1 and s2 reference to the same String object");
- else
- System.out.println("s1 and s2 reference to different String objects");
- }
- }
A.s1 and s2 reference to the same String object
B.s1 and s2 reference to different String objects
答:String str = "xxxxx"的实现过程:首先栈区创建str引用,然后在String池中寻找其指向的内容为"xxxxx"的对象,如果String池中没有,则创建一个,然后str指向String池中的对象,如果有,则直接将str指向"xxxxx"",不再重新创建对象;
8.What is the output of the following code?____A____
- public class Test {
- public static void main(String[] args) {
- String s1 = "Welcome to Java!";
- String s2 = s1;
-
- if (s1 == s2)
- System.out.println("s1 and s2 reference to the same String object");
- else
- System.out.println("s1 and s2 reference to different String objects");
- }
- }
A.s1 and s2 reference to the same String object
B.s1 and s2 reference to different String objects
9.An aggregation relationship is usually represented as ______A______.
A.a data field/the aggregating class
B.a data field/the aggregated class
C.a method/the aggregating class
D.a method/the aggregated class
答:聚合关系通常表示为数据字段/聚合类
1.Which of the following statements will convert a string s into i of int type?____ABCDE_____
A.i = Integer.parseInt(s);
B.i = (new Integer(s)).intValue();
C.i = Integer.valueOf(s).intValue();
D.i = Integer.valueOf(s);
E.i = (int)(Double.parseDouble(s));
答:Integer.parseInt() 是Integer包装类下的一个方法,作用是将()内的String类型字符串转化为int类型【parseInt (1010,2) 意思就是:输出2进制数1010在十进制下的数.】;intValue ()方法用于返回此Integer对象表示的值,该值转换为int类型 (通过强制转换)。
2.Which of the following statements are correct?___ABD_____
A.new java.math.BigInteger("343");
B.new java.math.BigDecimal("343.445");
C.new java.math.BigInteger(343);
D.new java.math.BigDecimal(343.445);
答:常用构造函数
BigDecimal(int)
创建一个具有参数所指定整数值的对象
BigDecimal(double)
创建一个具有参数所指定双精度值的对象
BigDecimal(long)
创建一个具有参数所指定长整数值的对象
BigDecimal(String)
创建一个具有参数所指定以字符串表示的数值的对
常用构造函数
1、BigInteger(byte[] val)
这个构造函数用于转换一个字节数组包含BigInteger的二进制补码,以二进制表示成一个BigInteger。
(用字节数组中值的ASCII码构造BigInteger)
2、BigInteger(int signum, byte[] magnitude)
此构造函数用于将BigInteger的符号大小表示法转换成一个BigInteger值。
(和第一种一样,增加了符号:1,0,-1)
3、BigInteger(int bitLength, int certainty, Random rnd)
此构造函数用于构造一个随机生成正BigInteger的可能是以指定的bitLength的素数。
(bitLength:返回的 BigInteger 的 bitLength;
certainty:调用方允许的不确定性的度量。新的 BigInteger 表示素数的概率超出 (1 - 1/2certainty)。此构造方法的执行时间与此参数的值是成比例的;
rnd:随机比特源,用这些随机比特选择用来进行质数测试的候选数。)
4、BigInteger(int numBits, Random rnd)
此构造函数用于构造一个随机生成的BigInteger,范围在0到 (2numBits - 1), 包括边界值。
5、BigInteger(String val)
此构造函数用于将十进制的字符串转换成一个BigInteger值表示形式。
6、BigInteger(String val, int radix)
这个构造函数用于将指定基数的数值字符串转换为BigInteger表示形式。
3.To add BigInteger b1 to b2, you write ____CD_____.
A.b1.add(b2);
B.b2.add(b1);
C.b2 = b1.add(b2);
D.b2 = b2.add(b1);
E.b1 = b2.add(b1);
答:要将 BigInteger b1 添加到 b2