Java复习题(三)阅读程序题_软件(总14页)
吊灯英文
《JAVA程序设计》复习题之(三)阅读程序题
三、程序阅读题
1.阅读以下程序
import .*;
public class Rever2 {
public static void main(String args[ ]){
int i,n=10;
int a[] = new int[10];
try {
BufferedReader br = new BufferedReader(
new InputStreamReader);
a[i] = () );
} catch (IOException e) { };
for (i= n-1; i >= 0; i=i-2)
" ");
}
独木造高楼没瓦没砖头人在水下走}
请写出该程序的功能:
该程序使用字符缓冲输入流从键盘输入10个数,然后倒序并间隔打印出来。
2.阅读以下程序
import .* ;
public class abc {
public static void main(String args[ ]) {
int i, s = 0 ;
int a[] = { 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120 };
for ( i = 0 ; i< ; i++ )
if (i % 3 == 0) s += a[i];
"s=" + s);
}
}
请写出该程序的输出结果:
翻过那座山作文s=260
3、阅读以下程序:
import .*;
自动对焦public class TestRandomAccess {
public static void main(String args[]) {
int data_arr[]={65,66,56,23,27,1,43,65,4,99};
try {
RandomAccessFile randf=new RandomAccessFile("","rw");
for (int i=0; i<; i++)
(data_arr[i]);
("Good morning!"); '
小小时代
for(int i=; i>=0; i=i-2) {
(i*4);
System,(" "+());
(40);
();
} catch (IOException e) {
"File access error: "+e);
}
}
}
该程序的输出结果是:
调的成语
电击女神
99 65 1 23 66 Good morning!
4、阅读以下程序并填空。
class _____________________ extends Exception {
String mymsg="我自己定义的异常!";
double mynum = ;
MyException () { super("首字母不能为A! ");}
MyException (String msg){_____________ } harAt(O)== 'A') {
MyException e = new MyException();
"kkkk:" + ());
();
System.out.println("*********in try*********");
__________________________; harAt(O)== 'B') {
throw new MyException ("第一个字符不应是B! ");
} el { }
} catch ( __________________________ ) {
();
"" + ());如何除锈
} catch( __________________________ ) {
"命令行参数个数错!");
}
}
}
程序填空:
MyException
super(msg)
throw e
MyException aaa
ArrayIndexOutOfBoundsException
5、阅读以下程序
import .*;
public class Test {
public static void main(String args[]) {
SubSubClass m=new SubSubClass(3,6,6);
();
}
}
class SuperClass {
int a,b;
SuperClass(int x,int y){ a=x; b=y; }
}
class SubClass extends SuperClass {
int c;
SubClass(int aa,int bb,int cc) {
super(aa,bb);
c = cc;
}
}
class SubSubClass extends SubClass {
int a;
SubSubClass(int aa,int bb,int cc) {
super(aa,bb,cc);
a = aa + bb + cc;
}
void show()
{ "a="+ a +"\nb="+ b +"\nc="+ c); }
}
请写出该程序的运行结果:
a=60
b=20
c=30
6、阅读以下程序
import .*;