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

java复习题

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

}

11. 下面程序分别用while 和for语句实现1~10累计求和。请在横线处填入适当内容完成程序。

Public class Sum {

public static void main(String args[]) {

System.out.println(“\\\\n*****while循环*****”); int n=10,sum=0;

while( ) {

sum+=n; n--; }

System.out.println(“sum is”+sum);

System.out.println(“\\\\n******for循环******”); sum=0;

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

sum+= i; }

System.out.println(“sum is”+sum); } }

12.设计一个窗口,上面有一个按钮。当鼠标移到按钮上时,立即隐藏该按钮;当鼠标离开按钮时,显示该按钮。请在横线处填入适当内容完成程序。

import java.awt.*; ; public class TestEvent { static Button bt = new Button(\隐藏按钮\ public static void main(String[] args) { Frame f1 = new Frame(); f1.setLocation(300, 300); f1.setSize(100,100); bt.addMouseListeneer (new MouseMove()); bt.setBackground(Color.cyan); bt.setBounds(new Rectangle(45, 100, 90, 30)); f1.add(bt); f1.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { ; } }); f1.setVisible(true); } } class MouseMove extends MouseAdapter{ public void mouseClicked(MouseEvent e) {

}

TestEvent.bt.setVisible(false); }

public void mouseExited(MouseEvent e) { ; }

13.分析下面的程序回答问题 public class Fib_d {

static int fib(int n) {

if ((n==0) || (n==1)) return n; else

return fib(n-2)+fib(n-1); }

public static void main(String args[]) {

int i;

for (i=0;i<6;i++) System.out.print(\ System.out.println(); } }

问:程序运行后输出结果是什么? 14.分析下面的程序,回答问题 import java.awt.*;

public class LoginFrame extends Frame {

public LoginFrame() {

super(\

this.setSize(200,120);

this.setBackground(Color.lightGray); this.setLocation(300,240);

this.setLayout(new FlowLayout());

this.add(new Label(\

this.add(new TextField(\ this.add(new Label(\ this.add(new TextField(10)); this.add(new Button(\ this.add(new Button(\ this.setVisible(true); }

public static void main(String arg[]) {

new LoginFrame();

} } 问:(1)该程序中用到哪些组件,写出它们的中文名称。

(2)程序中用到哪种类型的布局管理器,该种布局管理器是如何对组件布局的? 15. 分析下面的程序,回答问题 import java.io.*;

class FileInputStreamDemo { public static void main(String[] args) { String filename; int ch = 0;

filename = \

try { FileInputStream fis = new FileInputStream(filename); while ((ch = fis.read()) != -1) { System.out.print((char) ch); } fis.close(); } catch (IOException e) { System.out.println(\ } } }

问:程序的功能是什么?, import java.io.*;

public class FileOutputStreamDemo {

public static void main(String[] args) throws IOException { int n = 0; int num = 0; int i = 0;

String filename = \FileOutputStream fos = null; FileInputStream fis = null; try {

fos = new FileOutputStream(filename,true); for (n =100;n<=200;n++){ if (n % 3 ==0){

i++;

String str = String.valueOf(n); String str1 = str+\ \ byte[] buff = str1.getBytes(); fos.write(buff); if(i==0){ str = \ byte[] buf = str.getBytes(); fos.write(buf) }

} fos.close(); }

catch (FileNotFoundException e1) { System.out.println(e1); }

catch (IOException e2) { System.out.println(e2); } } }

问:程序的功能是什么?

1. 用递归调用求Fibonacci数的前5个数,(1,1,2,3,5)请将下面的程序填写完整。

public class Fibo {

public static void main(String args[]) {

final int n = ; for(int i = 1;i <= n;i++) {

System.out.print(\ ); if(i % 10 == 0)System.out.println(); } }

long f(long n){ if( )return 1; else return ; }

2. 请写出下面程序的运行结果 public class Test extends TT {

public void main(String args[]) {

Test t=new Test(\ }

public Test(String s) {

super(s);

System.out.println(\ }

public Test() {

this(\ } }

class TT {

public TT( ) {

System.out.println(\ }

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