没有合适的资源?快使用搜索试试~ 我知道了~
Java复习题(三)阅读程序题_软件.pdf
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 2 浏览量
2022-11-26
19:11:15
上传
评论
收藏 395KB PDF 举报
温馨提示
试读
16页
...
资源推荐
资源详情
资源评论
JAVA
程序设计》复习题之(三)阅读
程序题
三、程序阅读题
1
.阅读以下程序
import java.io.*;
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(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 {
RandomAccessFile randf=new RandomAccessFile("temp.dat","rw"); for (int i=0; i<data_arr.length; i++)
ran df.write In t(data_arr[i]);
ran df.writeUTF("Good morni ng!");' for(i nt i=data_arr.le ngth-l; i>=0; i=i-2) { ran df.seek(i*4);
System,out. prin t(" "+ra ndf.read In t()); ran df.seek(40);
System.out. println(ran df.readUTF()); ran df.close();
} catch (IOExce ptio n e) {
System.out. println ("File access error: "+e); }
}
}
该程序的输出结果是:
99 65 1 23 66 Good morni ng!
精选文库
4
、阅读以下程序并填空。
class ________________________________ exte nds Excep ti on {
String mymsg="
double mynum = 2.0;
MyException () { super(”
我自己定义的异常!
H.
首字母不能为
A! ")
;
}
调用父类构造方法
,
参数为
msgMyException (String msg){ _________________________} //
p ublic void dis playme() { System.out. prin tl n(m ymsg); } p ublic double mymethod() { retur n Math.sqrt( mynu m); }
}
class Excep ti on Test {
p ublic static void main( Stri ng[] args) {
try {
if ( args[O].charAt(O)== 'A') {
MyExce ptio n e = new MyExce pti on();
System.out. println ("kkkk:" + e.mymethod());
e.dis pl ayme();
System
.
out
.
println("*********in try*********");
______________________________ ;
//
抛出异常
e
} else if(args[O].charAt(O)== B) {
throw new MyExce pti on (”
第一个字符不应是
} else { System.out. prin tl n( args[0]); }
} catch ( ________________________________________ ) {
System.out .prin tl n( aaa.getMessage());
aaa.dis playme();
System.out. prin tl n("” + aaa.mymethod());
} catch( _________________________________________ ) {
System.out .prin tl n("
命令行参数个数错!
");
}
}
}
程序填空:
MyExce ptio n sup er(msg) throw e
MyExce ptio n aaa
Arra yin dexOutOfB oun dsExce ptio n
5
、阅读以下程序
import java.io.*
;
p ublic class Test {
p ublic static void main( Stri ng args[]) {
SubSubClass m=new SubSubClass(3,6,6); m.show();
}
}
class Sup erClass {
int a,b;
Sup erClass(i nt x,i nt y){ a=x; b=y; }
B!")
;
2
}
class SubClass exte nds Sup erClass {
int c;
SubClass(i nt aa,i nt bb,i nt cc) {
sup er(aa,bb);
c = cc;
}
}
class SubSubClass exte nds SubClass { int a
;
SubSubClass(i nt aa,i nt bb,i nt cc) { sup er(aa,bb,cc);
a = aa + bb + cc;
}
void show()
{ System.out. prin tl n( "a="+ a +"\nb="+ b +"\nc="+ c); } }
请写出该程序的运行结果:
a=60
b=20 c=30
6
、阅读以下程序
import java.io.*;
P ublic class abc {
p ublic static void main( Stri ng args[]) { String sl = "Hello!";
Stri ng s2 = new Strin g("World!"); System.out. prin tl n( sl.c on cat(s2));
}
}
请写出该程序的运行结果:
HelloWorld!
7
、阅读以下程序
import java.io.*;
p ublic class Classi {
p ublic static void main( Stri ng args[]){
int i
,
max, min
;
int a[] = {12,67,8,98,23,56,124,55,99,100);
max= mi n= a[0];
for(i=1; i<a.le ngth; i++){
if( a[i]< mi n) min = a[i];
if( a[i]> max) max = a[i];
}
System.out. prin tl n( max + " " + min);
System.out. prin tl n();
}
}
精选文库
3
请写出该程序完成的功能:
在数组中查找并输出最大值和最小值。
8
、阅读以下程序
import java.awt.*;
import java.a ppi et.A ppi et;
p ublic class DrawMylmage exte nds Applet {
Image mylmage; //
定义一个图像类
Image
的对象
mylmage
p ublic void in it(){
mylmage= getImage(getDocume ntBase()," pica.j pg");
}
p ublic void pain t(Gra phics g) {
g.drawlmage(mylmage,O,O,this);
}
}
请写出该程序的功能:
在
Applet
界面中显示当前文件夹下名为"
Pica.jpg
”的图像。
9
、阅读以下程序并填空。
import java.awt.*;
import java.a ppi et.*;
import java .n et.*;
p ublic class Mypicture _
App let {
Image image;
p ublic void______________
(){
try {
image=getlmage( new URL(getCodeBase(),'image.gif));
} ______________________ (MalformedURLExce pti on e) { }
p ublic void pain t(Gra phics g) {
g.drawlmage(image,O,O, _____________
}
p ublic void start() {
____________________ ();
}
}
程序填空题:
exte nds init catch this repaint
10
、阅读以下程序:
p ublic class Sum {
p ublic static void main( String args[]) { double sum = 0.0 ;
for ( int i = 1; i<= 100; i ++ )
sum += i;,
System.out .println( "sum=" + sum );
}
精选文库
4
剩余15页未读,继续阅读
资源评论
若♡
- 粉丝: 6197
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功