java数组与异常处理复习题(2)

2021-09-24 11:17

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; }


java数组与异常处理复习题(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2014年高考政治热点专题(1—3)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: