}
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; }
相关推荐: