11.Throwable类有两个子类:_____Error_____类和Exception类。
12.对程序语言而言,一般有编译错误和______运行______错误两类。
13.下面程序定义了一个字符串数组,并打印输出,捕获数组超越界限异常。请在横线处填入适当的内容完成程序。
public class HelloWorld
{
int i=0;
String greetings[]=
{
“Hello world!”,
“No,I mean it!”,
“HELLO WORLD!!”
};
while(i<4)
{
______try______
数组,异常处理,常用类。
}
System.out.println(greeting[i]);
}
_________catch________(ArrayIndexOutOfBoundsException e) {
System.out.println(“Re-setting Index Value”);
i=-1;
finally
{
System.out.println(“This is always printed”);
}
i++;
}
}
}
三、判断题
1.String str="abcdefghi"; char chr=str.charAt(9); ( × )
2.char[] chrArray={ 'a', 'b', 'c', 'd', 'e', 'f', 'g'}; char chr=chrArray[6]; ( √ )
3.int i,j; boolean booleanValue=(i==j); ( × )
4.int intArray[]={0,2,4,6,8}; int length=int Array.length();( × )
5.String str="abcedf"; int length=str.length; ( × )
6.int[] intArray[60]; ( × )
7.char[] str="abcdefgh"; ( × )
8.说明或声明数组时不分配内存大小,创建数组时分配内存大小。( √ )
9.Integer i = (Integer.valueOf("926")).intValue();( √ )
10.String s = (Double.valueOf("3.1415926")).toString(); ( √ )
11.Integer I = Integer.parseInt("926");( √ )
12.Arrays类主要对数组进行操作。( √ )
四、程序分析题
1.分析下面的程序,写出运行结果。
public class Exercises5_1 {
String str = new String("Hi !");
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 = "How are you";
ch[1] = 'u';
}
}
运行结果是:( Hi ! Luke )
2. 分析下面的程序,写出运行结果:
public class Exercises5_3 {
public static void main(String args[]) {
String str1 = new String();
String str2 = new String("String 2");
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("The String str1 is " + str1); System.out.println("The String str2 is " + str2); System.out.println("The String str3 is " + str3); System.out.println("The String str4 is " + str4); System.out.println("The String str5 is " + str5); System.out.println("The String strb is " + strb); }
}
运行结果是:( )
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.length;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; }
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说公务员考试java数组与异常处理复习题(2)在线全文阅读。
相关推荐: