第一范文网 - 专业文章范例文档资料分享平台

java数组与异常处理复习题

来源:用户分享 时间:2025/5/19 14:14:22 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

}

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=\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=\( × ) 6.int[] intArray[60]; ( × ) 7.char[] str=\( × )

8.说明或声明数组时不分配内存大小,创建数组时分配内存大小。( √ ) 9.Integer i = (Integer.valueOf(\( √ )

10.String s = (Double.valueOf(\( √ ) 11.Integer I = Integer.parseInt(\( √ ) 12.Arrays类主要对数组进行操作。( √ ) 四、程序分析题

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

搜索更多关于: java数组与异常处理复习题 的文档
java数组与异常处理复习题.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c0hi4z8epkb3uh255bmnh_2.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top