Java1试题加答案()(8)

2019-08-02 01:29

}

参考答案

一、 选择题答案 DDCDD CBDCAB 二、多项选择题答案

1.ACD 2.AB 3.AD 4.CD 5.AD 6.AC 7.AD 8.BC 9.BD 10.BCD 11.BD 12.ABD 13.BD 14.ABD 三、 填空题答案

填空第1题 Collection,List,Map,Set 填空第2题 7

填空第3题 因为在A的main方法中,还没有A的实例就要试图生成内部类的实例四、 编程题答案 编程第1题

import java.io.*; public class Point {

int x,y;

public Point(int x,int y) {

this.x = x; this.y = y; }

public Point getPoint() {

Point tempPoint = new Point(x,y); return tempPoint; }

public void setPoint(Point point) {

this.x = point.x;

36

this.y = point.y; }

public static void main(String args[]) {

Point Point1 = new Point(3,4);

System.out.println(\ Point Point2 = Point1.getPoint();

System.out.println(\ Point Point3 = new Point(5,6); Point1.setPoint(Point3);

System.out.println(\ } } 编程第2题

import java.io.*;

class FileCopy {

public static void main(String[] args) {

FileInputStream in; FileOutputStream out; if (args.length<2) {

System.out.println(\ System.exit(-1); } try {

in = new FileInputStream(args[0]); out = new FileOutputStream(args[1]); copyFile(in,out); }

catch (Exception e) {

System.out.println(e); } }

private static void copyFile(FileInputStream in, FileOutputStream out) {

int length;

byte buf[] = new byte[1024];

37

try{

while ((length=in.read(buf,0,1024))!=-1) {

out.write(buf, 0, length); } }

catch (Exception e)

{System.out.println(\ System.exit(-1); } } } 编程第3题

import java.awt.*; import java.awt.event.*; import java.applet.*; import java.util.*;

public class TimeViewer extends Applet implements ActionListener, Runnable {

Thread timer;

TextField in, out; Button bb;

Panel p1, p2, p3; boolean state;

public void init() {

in = new TextField(20); out = new TextField(20);

bb = new Button(\ p1 = new Panel(); p2 = new Panel(); p3 = new Panel();

setLayout(new GridLayout(3, 1)); setSize(200,100); p1.add(in); p2.add(bb); p3.add(out); add(p1); add(p2); add(p3);

bb.addActionListener(this); timer = new Thread(this);

38

state = true; timer.start(); }

public void actionPerformed(ActionEvent e) { //out.setText(in.getText()); out.setText(currentTime()); }

public void run() { while(true) { try {

timer.sleep(1000);

} catch (InterruptedException e) { } in.setText(currentTime());; } }

String currentTime() { Date now = new Date();

String str = now.getHours() + \now.getSeconds();

return str; } }

39


Java1试题加答案()(8).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:七年级英语下册词汇拼写专项练习

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: