}
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(\ }
相关推荐: