⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exam01_daan2.htm

📁 清华JAVA教程。不用多说了吧
💻 HTM
字号:
<html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><link rel="stylesheet" href="../../css/text.css" type="text/css"></head><body bgcolor="#FFFFFF" text="#000000" style="overflow-x:hidden"><center>  <table width="90%" border="0" cellspacing="0" cellpadding="0">    <tr>      <td class=text>         <p><b>四、 编程题答案</b></p>        <p>编程第1题<br>            import java.io.*;</p>        <p>  public class Point<br>            {<br>             int x,y;<br>          <br>            public Point(int x,int y)<br>            {<br>             this.x = x;<br>             this.y = y;<br>            }<br>          <br>            public Point getPoint()<br>            {<br>             Point tempPoint = new Point(x,y);<br>             return tempPoint;<br>             }<br>          <br>             public void setPoint(Point point)<br>             {<br>              this.x = point.x;<br>              this.y = point.y;<br>             }<br>          <br>          <br>             public static void main(String args[])<br>             {<br>              Point Point1 = new Point(3,4);<br>              System.out.println(&quot;Point1:&quot;+&quot;(&quot;+Point1.x+&quot;,&quot;+Point1.y+&quot;)&quot;);<br>          <br>              Point Point2 = Point1.getPoint();<br>              System.out.println(&quot;Point2:&quot;+&quot;(&quot;+Point2.x+&quot;,&quot;+Point2.y+&quot;)&quot;);<br>          <br>              Point Point3 = new Point(5,6);<br>              Point1.setPoint(Point3);<br>              System.out.println(&quot;Point1:&quot;+&quot;(&quot;+Point1.x+&quot;,&quot;+Point1.y+&quot;)&quot;);<br>             }  <br>          <br>            }<br>        </p>        <p><br>          编程第2题<br>            import java.io.*;</p>        <p>  class FileCopy<br>            {<br>             public static void main(String[] args)<br>             {<br>              FileInputStream in;<br>              FileOutputStream out;<br>          <br>              if (args.length&lt;2)<br>             {<br>              System.out.println(&quot;Usage: java copy srcfile destfile&quot;);<br>              System.exit(-1);<br>             } <br>          <br>             try <br>             {<br>              in = new FileInputStream(args[0]);<br>              out = new FileOutputStream(args[1]);<br>              copyFile(in,out);<br>          <br>             }<br>          <br>             catch (Exception e)<br>             {<br>              System.out.println(e);<br>             }<br>          <br>            }</p>        <p>    private static void copyFile(FileInputStream in, FileOutputStream           out)<br>             {<br>              int length;<br>              byte buf[] = new byte[1024];<br>            <br>              try{<br>                while ((length=in.read(buf,0,1024))!=-1)<br>              {<br>               out.write(buf, 0, length);<br>              }<br>          <br>             } <br>          <br>             catch (Exception e)<br>             {<br>              System.out.println(&quot;Error:&quot;+e);<br>              System.exit(-1);<br>             }<br>            }<br>          <br>           }<br>        </p>        <p><br>          编程第3题<br>            import java.awt.*;<br>            import java.awt.event.*;<br>            import java.applet.*;<br>            import java.util.*;</p>        <p>  public class TimeViewer extends Applet implements ActionListener,           Runnable {<br>          <br>             Thread timer;<br>             TextField in, out;<br>             Button bb;<br>             Panel p1, p2, p3;<br>             boolean state;<br>          <br>             public void init() { <br>              in = new TextField(20); <br>              out = new TextField(20);<br>              bb = new Button(&quot;Current Time:&quot;);<br>              p1 = new Panel();<br>              p2 = new Panel();<br>              p3 = new Panel();<br>          <br>              setLayout(new GridLayout(3, 1));<br>              setSize(200,100);<br>          <br>              p1.add(in);<br>              p2.add(bb);<br>              p3.add(out);<br>              add(p1);<br>              add(p2);<br>              add(p3);<br>          <br>              bb.addActionListener(this); <br>          <br>              timer = new Thread(this);<br>              state = true;<br>              timer.start(); <br>             }<br>          <br>             public void actionPerformed(ActionEvent e) {<br>              //out.setText(in.getText());<br>              out.setText(currentTime()); <br>             }<br>          <br>             public void run() {<br>              while(true) {<br>              try { <br>                 timer.sleep(1000); <br>              } catch (InterruptedException e) { }<br>              in.setText(currentTime());;<br>              }<br>            }<br>          <br>            String currentTime() {<br>             Date now = new Date();<br>             String str = now.getHours() + &quot;:&quot; + now.getMinutes() +           &quot;:&quot; + now.getSeconds();<br>             return str;<br>            }<br>                     }</p>        </td>  </tr></table>  </center></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -