1.下面哪几个选项是合法的数组申明?ABD
A.int[] array[];
B.char[] Chars_one;
C.int[10] Int_one;
D.Student myStudents[];
E.Student myStudents[12];
2.下面哪些选项声明了一个数组并用5个数对数组进行初始化?BD
A.Array a = new Array(5);
B.int[] a = {23, 22, 21, 20, 19};
C.int[] array;
D.int array[] = new int[5];
E.int a[] = new int(5);
F.int[5] array;
3.关于数组元素默认初始化,下面哪些选项是正确的?CD
A.int -> -1
B.String -> ""
C.Person -> null
D.char -> '\u0000'
E.float -> 0.0
F.boolean -> true
4.针对下面的代码,下面哪个叙述是正确的?C
public class TestClass { static int len[] = new int[10]; public static void main(String[] args) { System.out.println(len[1]); } }
A.编译时将发生错误
B.编译时正确但是运行时候出错
C.输出为0
D.输出为null
5.给定下面的程序,哪些说法是正确的?E
public class MyClass { public static void main(String[] args) { String[] mychars = {"a", "b", "c", "d"}; if (args.length == 0) { System.out.println("no result"); } else { System.out.println(mychars[args.length] + " result"); } } }
A.该代码无法编译
B.不带任何程序参数运行,将会抛出NullPointerException
C.分别带0个参数、3个参数运行该程序,会打印no result和b result
D.分别带0个参数、3个参数运行该程序,会打印no result和c result
E.分别带0个参数、3个参数运行该程序,会打印no result和d result
F.分别带0个参数、3个参数运行该程序,会打印a arguments和b arguments
6.编程题:求一个长度为10的整型数组中的最大元素,采用随机赋值的方式并输出各元素的值。
public class MaxArray { public static void main(String[] args) { int[] a = new int[10]; setValue(a); showValue(a); System.out.println("\nmax: " + getMaxValue(a)); } public static int getMaxValue(int[] a) { int max = a[0]; for (int i = 0; i < a.length; i++) { if (a[i] > max) { max = a[i]; } } return max; } public static void setValue(int[] a) { for (int i = 0; i < a.length; i++) { a[i] = (int) (Math.random() * 100); } } public static void showValue(int[] a) { for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } } }
7.仔细分析下面给出的程序,输出的运行结果是多少?A
B.no
C.编译错误
D.运行时发生异常
8.下面的哪些选项插入到程序的第7行,程序可以编译通过?ABEF
9.下面哪个选项对数组的声明、创建和初始化是合法的?D
10.根据下面的声明,假设已经初始化了该数组,则哪个表达式会返回数组的大小?C
int[][] array = new int[5][];
A.array[].length()
B.array.length()
C.array[2].length
D.array[0][0].length
E.array[3].size()