第一范文网 - 专业文章范例文档资料分享平台

《Java程序设计》练习题

来源:用户分享 时间:2025/7/5 10:26:12 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

}catch(Exception e){

System.err.println(e.getMessage()); // 2 }

finally{

System.out.println(\ } }

public static void method1() throws Exception { method2(); //4 }

public static void method2() throws Exception { method3(); //5 }

public static void method3() throws Exception{

throw new Exception( \ } }

34、阅读下面的程序:

public class Timer extends Thread{ int time=0;

public Timer(int time) { this.time=time; }

public void run(){ try{

for(int i=0;i

System.out.print (i+“-”); } }

catch(Exception e) {

System.out.println(e.toString()); } }

public static void main(String args[]){ Timer timer=new Timer(10); timer.start(); } }

以上程序经编译后运行结果是:

五、程序填空题

1、阅读下面的程序,写出带划线语句的注释,并写出运行结果。

第 33 页 共 48 页

import java.awt.*; import javax.swing.*;

public class Test {// 继承JFrame private int screenOffset = 80; public Test(){

super( \ ; // 设置JFrame的大小为300*300 show(); // }

public void paint( Graphics g ){

for ( int i = 1; i <= 8; i++ ) {

int origin = screenOffset + 80 - i * 10; g.drawOval(origin, origin, i * 20, i * 20); } }

public static void main( String args[] ){ Test application = new Test();

application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE ); } }

2、阅读下面的程序,写出带划线语句或注释,并写出该程序的作用: import java.io.*; public class Test {

public static void main(String args[]) { scanFiles(\ }

public static void scanFiles(String path) { if (path == null) return;

File f = new File(path); // if (!f.exists()) return;

if (f.isFile()) // System.out.println(f.getAbsolutePath()); else {

File dir[] = f.listFiles(); for (int i = 0; i < dir.length; i++)

scanFiles(dir[i].getAbsolutePath());// } } }

3、仔细阅读下面的程序代码,请将划线上①~⑤的语句补充完整。

第 34 页 共 48 页

abstract class Person{

private String name;

public Person(String n){ name = n; }

public ____①________ String getDescription(); public ____②_________ (){ return name; } }

class Student ____③ _________ Person{

private String major;

public Student(String n, String m){ super(n); major = m; }

public String ____④_________(){ return \学生专业是:\ } }

public class TestPerson{

public static void main(____⑤________){

Person p = new Student(\王甜甜\计算机科学\

System.out.println(p.getName() + \ } }

4、阅读下面的程序MyAdd.java,填写划线部分的语句或注释,并写出程序执行结果。 public class MyAdd { //继承线程类 static int total = 10; int n;

public MyAdd(int n){

this.n=n; }

public void run() { try{

sleep(n); //含义是: total=total+n;

第 35 页 共 48 页

System.out.println(total); }

catch(Exception e){

System.out.println(“EXCEPTION!”); }

}

public static void main(String[] args) { MyAdd t1 = new MyAdd(3000);

; //启动线程t1 } }

5、阅读下面的程序Test.java,先填写空格的内容,然后写出运行结果:

21) import java.io.*; 22) public class Test{

23) public static void main(String argv[]){

24) ; //创建Test对象,对象名为t 25) System.out.println(t.fliton()); 26) }

27) public int fliton(){ 28) try{

//第9行的含义是: 29) FileInputStream din = new FileInputStream(\30) din.read();

31) }catch(IOException ioe){ //第11行的含义是: 32) System.out.println(\33) return -1; 34) }

35) finally{

36) System.out.println(\37) }

38) return 0; 39) } 40) }

如果文件test.txt与Test.java在同一个目录下,test.txt中仅有一行字符串“hello world!”,运行结果是什么?

6、阅读下面的程序代码,根据注释要求补充、完成代码(划线是需要补充的地方),最后简要说明该程序的功能。

1. ___________________{ //声明一个接口,接口名为Area 2. public double CalsulateArea(); 3. }

4. class MyCircle implements Area{ 5. double r;

第 36 页 共 48 页

搜索更多关于: 《Java程序设计》练习题 的文档
《Java程序设计》练习题.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c9s2wo87vyl68ub00wplg_9.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top