Java复习题阅读程序题软件

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

《JAVA程序设计》复习题之(三)阅读程序题三、程序阅读题

1.阅读以下程序

import .*;

public class Reverse2 {

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=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) {

}

}

}

该程序的输出结果是:

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();

();

System.out.println("*********in try*********");

__________________________; harAt(O)== 'B') {

throw new MyException ("第一个字符不应是B! ");

} 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 + b

b + cc;

}

void show()

}

请写出该程序的运行结果:

a=60

b=20

c=30

6、阅读以下程序

import .*;

public class abc {

public static void main(String args[]) { String sl = "Hello!";

String s2 = new String("World!");

相关文档
最新文档