4.已知byte i = (byte)127; i = i +1;这两个语句能被成功编译。( √ )
5.String str=\char chr=str.charAt(9); ( × ) 6.char[] chrArray={ 'a', 'b', 'c', 'd', 'e', 'f', 'g'}; char chr=chrArray[6]; ( √ )
7.int i,j; boolean booleanValue=(i==j); ( × )
8.int intArray[]={0,2,4,6,8}; int length=int Array.length();( × )
9.String str=\( × )
10.short shortValue=220; byte byteValue=shortValue; ( × ) 11.int[] intArray[60]; ( × )
12.char[] str=\( × )
13.说明或声明数组时不分配内存大小,创建数组时分配内存大小。( √ )
14.强制类型转换运算符的功能是将一个表达式的类型转换为所指定的类型。( √ ) 四、分析题
1.分析下面的程序,写出运行结果。 public class Exercises5_1 {
String str = new String(\ char[] ch = { 'L', 'i', 'k', 'e' };
public static void main(String args[]) { Exercises5_1 ex = new Exercises5_1(); ex.change(ex.str, ex.ch); System.out.print(ex.str + \ System.out.print(ex.ch); }
public void change(String str, char ch[]) { str = \ ch[1] = 'u'; } }
运行结果是:( Hi ! Luke )
2.分析下面的程序,写出运行结果。 public class Exercises5_2 {
public static void main(String[] args) { int n = 1, m, j, i; for (i = 3; i <= 30; i += 2) { m = (int) Math.sqrt((double) i); for (j = 2; j <= m; j++) if ((i % j) == 0) break; if (j >= m + 1) { System.out.print(i + \
if (n % 5 == 0) System.out.print(\ n++; } } } }
运行结果是:( )
3 5 7 11 13 17 19 23 29
3.分析下面的程序,写出运行结果: public class Exercises5_3 { public static void main(String args[]) { String str1 = new String(); String str2 = new String(\ char chars[] = { 'a', ' ', 's', 't', 'r', 'i', 'n', 'g' }; String str3 = new String(chars); String str4 = new String(chars, 2, 6); byte bytes[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39 }; String str5 = new String(bytes); StringBuffer strb = new StringBuffer(str3); System.out.println(\ System.out.println(\ System.out.println(\ System.out.println(\ System.out.println(\ System.out.println(\ }
}
运行结果是:( )
The String str1 is
The String str2 is String 2 The String str3 is a string The String str4 is string The String str5 is 0123456789 The String strb is a string
五、改错题
1.找出下面代码的错误部分,说明错误类型及原因,并更正。
public int m1 (int number[20]){ number = new int[20]; for(int i=0;i number[i] = number[i-1] + number[i+1]; return number; } 改正后程序: public int[] m1(int number[]) { // number = new int[20]; for (int i = 1; i < number.length - 1; i++) } number[i] = number[i - 1] + number[i + 1]; return number; 2.找出下面代码的错误部分,说明错误类型及原因,并更正。 (1) int x = 1; while (x <= 10); { i++; } 改正后程序: int x = 1, i = 0; while (x <= 10) { i++; } (2) switch (n) { case 1: system.out.println(\ case 2: system.out.println(\ break; } 改正后程序: int n = 1; switch (n) { case 1: System.out.println(\); break; System.out.println(\); break; } case 2: 六、简答题 1.Java的关键字有哪些? 2.标识符有何用途?Java中定义标识符的规则有哪些? 3.Java定义了哪些基本数据类型?基本数据类型和引用数据类型的特点是什么?字节型和字符型数据有何区别?长度为32位的基本数据类型有哪些? 4.整型常量有哪三种表示形式?浮点型变量有哪两种表示形式?布尔型常量可以转换成其他数据类型吗? 5.在Java 语言中,表示字符串常量和字符常量时应注意哪些问题? 6.在Java转义字符表示中,ASCII码值对应的字符如何表示?Unicode字符集中对应的字符如何表示? 7.什么是表达式语句?什么是空语句?什么是块语句?可以把块语句视为一条语种吗? 8.if语句中,<条件表达式>一定是逻辑型表达式吗? switch语句中,<语句序列>里一定有break语句吗? 9.while循环语句与do-while循环语句有何不同? 10.for循环语句中,关键字for后面括号内的表达式是否可以使用多个用逗号分隔的表达式?for-each语句的特点是什么? 11.break语句和continue语句有哪两种形式? 12.创建数组元素为基本数据类型的数组时,系统都会指定默认值吗?布尔型的默认值是什么? 13.在Java中怎样定义和使用一维数组、二维数组? 14.字符串类String 和StringBuffer类有何不同? 15.Java中的数组实际上是一个隐含的“数组类”的对象,而数组名实际上是该对象的一个引用,这种说法对吗? 16.字符数组与字符串有本质的不同,而字符串实际上是String类和StringBuffer类的对象,这种说法对吗? 七、编程题 1.编写一个程序,求1!+2!+?+10!的值。 2.编程求100以内的全部素数。 3.使用异或运算符“^”实现两个整数的交换。 4.编写一个程序,打印输出下列5×5螺旋方阵: 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9 5.给出任意两个日期,编程计算它们相距的天数。 6.编程输出下列图形: * *** ***** *** * 7.编程验证哥德巴赫猜想,即任何大于6的偶数可以表示为两素数之和,如10=3+7。 8.百鸡百钱问题,公鸡每只3元,母鸡每只5元,小鸡3只1元,用100元钱买100只鸡,公鸡、母鸡和小鸡各买多少? 9.编写一个程序,利用数组把10个数用直接交换方法从小到大排序。 10.编写一个程序,用选择法对数组a[]={9, 5, 3, 12, 22, 35, 88, 11, 90, 1}进行由小到大的排序。 11.找出一个二维数组的鞍点,即该位置上的元素在该行上最大、在列上最小(也可能没有)。 12.编写一个程序,打印输出10行杨辉三角形。 13.编写一个程序,实现字符串的大小写字母的相互转换。 14.编写一个程序,找出两个字符串中所有相同的字符。 15.编写一个程序,对字符串数组按字典序重新排列。 16.编写一个程序,分析输出字符串中的单词,并统计单词个数。 17.编写一个程序,将字符串“.ymene tsrow sih si nam yrevE”反转。 第3章 Java语言面向对象基础 习 题 三 一、填空题 1.类是一组具有相同(属性)和(行为)的对象的抽象。(实例)是由某个特定的类所描述的一个个具体的对象。 2.(接口)只描述系统所提供的服务,而不包含服务的实现细节。 3.模型应具有(抽象性)、(可理解性)、(精确性)、(确定性)和廉价性等基本特性。 4.UML定义了(用例图)、(静态图)、(交互图)、行为图和实现图五类模型图。 5.在UML类图中分别用( + )、( # )、( ~ )和( - )表示属性与方法的公有、保护、默认和私有访问控制权限。 6.在UML中,类之间主要有(关联)、(依赖)、(聚集)、(泛化)和实现五种关系。 7.构造方法的方法名与(类名)相同,若类中没有定义任何的构造方法,则运行时系统会自动为该类生成一个(默认构造)方法。 8.在方法体内定义的变量是(局部变量),其前面不能加(public),且必须(初始化)。 9.数组元素作实参时对形参变量的数据传递是(单向值传递),数组名作实参时对形参变量的数据传递是(双向引用传递)。 10.对象作方法形参时,方法实参也用对象,实现(引用)调用。 11.( new)是一个特殊的方法,用于创建一个类的实例。 12.对象拷贝有(对象引用复制)、(浅复制)和(深复制)三种。 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库习题解答(2)在线全文阅读。
相关推荐: