没有合适的资源?快使用搜索试试~ 我知道了~
Java复习题(三)阅读程序题-软件.doc
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 119 浏览量
2021-10-11
17:47:46
上传
评论
收藏 54KB DOC 举报
温馨提示
试读
16页
Java复习题(三)阅读程序题-软件.doc
资源推荐
资源详情
资源评论
《JAVA 程序设计》复习题之〔三〕阅读程序题
三、程序阅读题
1.阅读以下程序
import java.io.*;
public class Reverse2 {
public static void main(String args[ ]){
int i,n=10;
int a[] = new int[10];
try {
Bu&eredReader br = new Bu&eredReader(
new InputStreamReader(System.in));
a[i] = Integer.parseInt(br.readLine() );
} catch (IOException e) { };
for (i= n-1; i >= 0; i=i-2)
System.out.print(a[i]+" ");
System.out.println();
}
}
请写出该程序的功能:
该程序使用字符缓冲输入流从键盘输入 10 个数,然后倒序并间隔打印出来。
2.阅读以下程序
import java.io.* ;
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< a.length ; i++ )
if (i % 3 == 0) s += a[i];
System.out.println("s=" + s);
}
}
请写出该程序的输出结果:
s=260
3、阅读以下程序:
import java.io.*;
public class TestRandomAccess {
public static void main(String args[]) {
int data_arr[]={65,66,56,23,27,1,43,65,4,99};
try {
1 / 16
RandomAccessFile randf=new RandomAccessFile("temp.dat","rw");
for (int i=0; i<data_arr.length; i++)
randf.writelnt(data_arr[i]);
randf.writeUTF("Good morning!"); '
for(int i=data_arr.length-l; i>=0; i=i-2) {
randf.seek(i*4);
System,out.print(" "+randf.readInt());
randf.seek(40);
System.out.println(randf.readUTF());
randf.close();
} catch (IOException e) {
System.out.println("File access error: "+e);
}
}
}
该程序的输出结果是:
99 65 1 23 66 Good morning!
4、阅读以下程序并填空。
class _____________________ extends Exception {
String mymsg="我自己定义的异常!";
double mynum = 2.0;
MyException () { super("首字母不能为 A! ");}
MyException (String msg){_____________ } //调用父类构造方法,参数为 msg
public void displayme() { System.out.println(mymsg); }
public double mymethod() { return Math.sqrt(mynum); }
}
class ExceptionTest {
public static void main(String[] args) {
try {
if ( args[O].charAt(O)== 'A') {
MyException e = new MyException();
System.out.println("kkkk:" + e.mymethod());
e.displayme();
System.out.println("*********in try*********");
__________________________; //抛出异常 e
} else if(args[O].charAt(O)== 'B') {
throw new MyException ("第一个字符不应是 B! ");
} else { System.out.println(args[0]); }
} catch ( __________________________ ) {
System.out.println(aaa.getMessage());
aaa.displayme();
System.out.println("" + aaa.mymethod());
} catch( __________________________ ) {
2 / 16
System.out.println("命令行参数个数错!");
}
}
}
程序填空:
MyException
super(msg)
throw e
MyException aaa
ArrayIndexOutOfBoundsException
5、阅读以下程序
import java.io.*;
public class Test {
public static void main(String args[]) {
SubSubClass m=new SubSubClass(3,6,6);
m.show();
}
}
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()
{ System.out.println("a="+ a +"\nb="+ b +"\nc="+ c); }
}
请写出该程序的运行结果:
a=60
b=20
c=30
3 / 16
6、阅读以下程序
import java.io.*;
public class abc {
public static void main(String args[]) {
String sl = "Hello!";
String s2 = new String("World!");
System.out.println(sl.concat(s2));
}
}
请写出该程序的运行结果:
Hello!World!
7、阅读以下程序
import java.io.*;
public class Class1 {
public static void main(String args[]){
int i,max,min;
int a[] = {12,67,8,98,23,56,124,55,99,100);
max= min= a[0];
for(i=1; i<a.length; i++){
if( a[i]< min) min = a[i];
if( a[i]> max) max = a[i];
}
System.out.println( max + " " + min);
System.out.println();
}
}
请写出该程序完成的功能:
在数组中查找并输出最大值和最小值。
8、阅读以下程序
import java.awt.*;
import java.applet.Applet;
public class DrawMylmage extends Applet {
Image myImage; //定义一个图像类 Image 的对象 myImage
public void init(){
myImage= getImage(getDocumentBase(),"pica.jpg");
}
public void paint(Graphics g) {
g.drawImage(myImage,0,0,this);
}
}
请写出该程序的功能:
在 Applet 界面中显示当前文件夹下名为“pica.jpg〞的图像。
4 / 16
剩余15页未读,继续阅读
资源评论
huayuya123
- 粉丝: 26
- 资源: 31万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功