出自:国家开放大学面向对象程序设计

假定一个字符串对象x的值为"abcdef\n",则x.substring(0,4)的值为( )。
【A.】"a"
【B.】"abcdf"
【C.】"bcde"
【D.】"abcd"
假定要访问一维数组x中的第k个元素,则对应的元素(下标变量)表示为( )。
【A.】x.[k]
【B.】x[k]
【C.】x[k-1]
【D.】x[k+1]
在Java语言中,定义有两个字符串类,其类名分别为String和( )。
【A.】Buffer
【B.】char[]
【C.】StringBuffer
【D.】char*
假定一个字符串对象x的值为"abcdef\n",则x.length()的值为( )。
【A.】5
【B.】6
【C.】7
【D.】8
public class XXK4 {
public static void main(String[] args) {
int []a={2,5,8,10,15,20};
int s=0;
for(int i=0; i<a.length; i++) s+=a[i];
System.out.println("s="+s);
}
}

【A.】s=90
【B.】s=60
class ABC {
String name;
double price;
public ABC(String na, double pr) {name=na; price=pr;}
public int compareTo(ABC x) {
if(name.compareTo(x.name)>0) return 1;
if(name.compareTo(x.name)<0) return -1;
else return 0;
}
}
public class XXK5 {
public static void main(String[] args) {
String []s={"apple", "pear", "tangerme", "banana", "grape"};
double []d={3.8, 2.5, 3.2, 4.3, 5.2};
ABC []ar=new ABC[s.length];
int i,k=0;
for(i=0; i<ar.length; i++)
ar[i]=new ABC(s[i],d[i]);
for(i=1; i<ar.length; i++)
if(ar[i].compareTo(ar[k])>0) k=i;
System.out.println(ar[k].name+" "+ar[k].price);
}
}

【A.】tangerme 3.2
【B.】tangerme 3.3
public class XXK4 {
public static void main(String[] args) {
int [][]a=//;
int []b=new int[3];
int i,j;
for(i=0; i<a.length; i++)
for(j=0; j<a[i].length; j++)
b[i]+=a[i][j];
for(i=0; i<b.length; i++)
System.out.print(b[i]+" ");
}
}

【A.】15 19 15
【B.】15 18 15
class ABC {
private int []a;
public ABC(int []aa) {a=aa;}
public int minValue() {
int min=a[0];
for(int i=1; i<a.length; i++)
if(a[i]<min) min=a[i];
return min;
}
}
public class XXK5 {
public static void main(String[] args) {
int []a={20,29,18,25,16,38,24,30};
ABC x=new ABC(a);
int min=x.minValue();
System.out.println("min: "+min);
}
}

【A.】min 18
【B.】min 16
class ABC {
int a,b;
public ABC(int a, int b) {this.a=a; this.b=b;}
public int compareTo(ABC x) {return a*b-x.a*x.b;}
}
public class XXK5 {
public static void main(String[] args) {
int [][]d=//;
ABC []ar=new ABC[d.length];
int i,k=0;
for(i=0; i<ar.length; i++)
ar[i]=new ABC(d[i][0],d[i][1]);
for(i=1; i<ar.length; i++)
if(ar[i].compareTo(ar[k])>0) k=i;
System.out.println("k="+k);
}
}

【A.】k=2
【B.】k=4
class ABC {
String name;
double price;
public ABC(String na, double pr) {name=na; price=pr;}
public int compareTo(ABC x) {
if(price>x.price) return 1;
if(price<x.price) return -1;
else return 0;
}
}
public class XXK5 {
public static void main(String[] args) {
String []s={"apple", "pear", "tangerme", "banana", "grape"};
double []d={3.8, 2.5, 3.2, 4.3, 5.2};
ABC []ar=new ABC[s.length];
int i,k=0;
for(i=0; i<ar.length; i++)
ar[i]=new ABC(s[i],d[i]);
for(i=1; i<ar.length; i++)
if(ar[i].compareTo(ar[k])>0) k=i;
System.out.println(ar[k].name+" "+ar[k].price);
}
}

【A.】grape 5.2
【B.】grape 5.3
class ABC {
private int []a;
public ABC(int []aa) {a=aa;}
public int maxValue() {
int max=a[0];
for(int i=1; i<a.length; i++)
if(a[i]>max) max=a[i];
return max;
}
}
public class XXK5 {
public static void main(String[] args) {
int []a={5,9,13,25,16,38,26,30};
ABC x=new ABC(a);
int max=x.maxValue();
System.out.println("max: "+max);
}
}

【A.】max: 38
【B.】max: 40
public class XXK4 {
public static void main(String[] args) {
int []a=new int[6];
int i,s=0;
for(i=1; i<a.length; i++) a[i]=a[i-1]+2;
for(i=0; i<a.length; i++) s+=a[i];
System.out.println("s="+s);
}
}

【A.】s=30
【B.】s=60
public class XXK4 {
public static void main(String[] args) {
int [][]a=new int[2][3];
int i,j,s=0;
for(i=0; i<a.length; i++)
for(j=0; j<a[i].length; j++)
a[i][j]=(i+1)*(j+1);
for(i=0; i<a.length; i++) s+=a[i][2];
System.out.println("s="+s);
}
}

【A.】s=8
【B.】s=9
class ABC {
int a,b;
public ABC(int a, int b) {this.a=a; this.b=b;}
public int compareTo(ABC x) {return a*b-x.a*x.b;}
}
public class XXK5 {
public static void main(String[] args) {
int [][]d=//;
ABC []ar=new ABC[5];
int i,k=0;
for(i=0; i<d.length; i++)
ar[i]=new ABC(d[i][0],d[i][1]);
for(i=1; i<ar.length; i++)
if(ar[i].compareTo(ar[k])>0) k=i;
System.out.println("k="+k);
}
}

【A.】k=2
【B.】k=3
public class XXK4 {
public static void main(String[] args) {
String []a={"xxk","weirong","xucong","xuxiaohua","baojuan"};
int m=0;
for(int i=0; i<a.length; i++) {
int n=a[i].length();
if(n>m) m=n;
}
System.out.println("m="+m);
}
}

【A.】m=10
【B.】m=9
public class XXK4 {
public static void main(String[] args) {
int [][]a=//;
int s=0;
for(int i=0; i<a.length; i++)
for(int j=0; j<a[i].length; j++)
s+=a[i][j];
System.out.println("s="+s);
}
}

【A.】s=48
【B.】s=49
下列哪个类不是异常类的父类?( )。
【A.】Error
【B.】Throwable
【C.】Exception
【D.】Object
在Java语言中,把生成异常对象并提交的过程称为( )一个异常。
【A.】编码
【B.】检查
【C.】抛出
【D.】生产
下面的关键字( )与异常处理无关。
【A.】throw
【B.】throws
【C.】import
【D.】finally
在Java语言中,Exception下的异常分为两类:即检查型异常和( )型异常。
【A.】编码
【B.】重大
【C.】非检查
【D.】逻辑
下面的关键字( )与异常处理无关。
【A.】switch
【B.】catch
【C.】try
【D.】finally
在Java语言中,从生成异常的方法开始进行回溯,直到找到包含相应异常处理的方法为止,我们把这一过程称为( )一个异常。
【A.】编码
【B.】检查
【C.】捕获
【D.】生产
下面的异常( )为输入输出访问异常。
【A.】NullPointerException
【B.】FileNotFoundException
【C.】ArrayIndexOutOfBoundsException
【D.】IOException
下面的异常( )为数组下标越界异常。
【A.】ArithmeticException
【B.】NullPointerException
【C.】ArrayIndexOutOfBoundsException
【D.】FileNotFoundException
下面的异常( )为文件没有找到异常。
【A.】NullPointerException
【B.】FileNotFoundException
【C.】ArrayIndexOutOfBoundsException
【D.】IOException
在Java语言中,程序运行时发生的运行错误又分为致命性的严重错误和非致命性的一般错误两种,异常属于( )错误。
【A.】编码
【B.】检查
【C.】致命性
【D.】一般
Exception类是所有( )类的父类,用户自定义的所有异常类都必须是( )类的子类。
【A.】异常 Exception
【B.】检查 Error
【C.】致命性 Exception
【D.】对象 Exception
通常程序中的错误可以分为三种类型,即编译错误,运行错误和( )错误。
【A.】编码
【B.】重大
【C.】逻辑
【D.】检查
在Java语言中,( )型异常继承自RuntimeException类的异常。
【A.】编码
【B.】实时检查
【C.】非检查
【D.】人工逻辑
下面的选项(  )不属于非检查型异常。
【A.】数组越界
【B.】除零
【C.】空值操作
【D.】异常
下面的关键字( )与异常处理无关。
【A.】throw
【B.】void
【C.】throws
【D.】try
在Java语言中,捕获和处理异常的语句块为( )。
【A.】try…catch
【B.】switch…case
【C.】if…else
【D.】do…while
在一个方法的定义中,若不想在方法体内捕获和处理异常,把出现的异常抛给调用该方法的程序,则必须在方法头的末尾使用( )子句抛出异常。
【A.】throws
【B.】check
【C.】DoException
【D.】error
输入流类(InputStream)和输出流类(OutputStream)是java.io包中所有( )流的抽象基类。
【A.】容器
【B.】字符
【C.】字节
【D.】代码
读出器类(Reader)和写入器类(Writer)是java.io包中所有( )流的抽象基类。
【A.】容器
【B.】字符
【C.】异常
【D.】文件
Java语言中的标准输出流为( )。
【A.】System.in
【B.】StdInputStream
【C.】OutputStream
【D.】System.out
Java语言中的标准输入流为( )。
【A.】System.in
【B.】StdInputStream
【C.】OutputStream
【D.】System.out
DataInputStream类的文件流只能够从二进制文件中读出一种基本类型的数据。
【A.】√
【B.】×
输入流类(InputStream)和输出流类(OutputStream)是用来处理字符流的抽象基类。
【A.】√
【B.】×
CharArrayWriter和BufferedWriter类的构造函数的参数不需要一个文本文件名。
【A.】√
【B.】×
当一个方法进行文件访问操作可能生成一个IOException异常时,该方法可以在方法头声明抛出该异常,也可以采用try…catch块捕获并处理该异常。
【A.】√
【B.】×
输入流类(InputStream)和输出流类(OutputStream)是用来处理字节流的抽象基类。
【A.】√
【B.】×
java.io包中提供的ObjectOutputStream类能够把对象信息存储到文件中。
【A.】√
【B.】×
在对文件进行的输入/输出(I/O)方法的调用中,当遇到错误时通常会抛出除IOException异常之外的其他异常。
【A.】√
【B.】×
文件输出流类(FileOutputStream)和数据输出流类(DataOutputStream)不是OutputStream类的子类。
【A.】√
【B.】×
在Java中将信息的输入与输出过程抽象为输入/输出流。输入是指数据流入程序,输出是指数据从程序流出。
【A.】√
【B.】×
在Java语言中,只能对文件存取字符或字节信息,不能存储对象信息。
【A.】√
【B.】×
文件输入流类(FileInputStream)和数据输入流类(DataInputStream)不是InputStream类的子类。
【A.】√
【B.】×
java.io包中提供的ObjectInputStream类能够从文件中读取对象类型的信息。
【A.】√
【B.】×
当一个方法进行文件访问操作可能生成一个IOException异常时,该方法必须在方法头声明抛出该异常,别无其他选择。
【A.】√
【B.】×