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

📄 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"><center><table width="95%" border="0" cellspacing="0" cellpadding="0">  <tr>      <td class=text>         <p><b>四、 编程题答案</b></p>        <p>1<br>           public class HelloWorld<br>            { <br>            public static void main(String args[])<br>            {<br>             System.out.println(&quot;Hello,World!&quot;);<br>            }<br>           }</p>        <p> import java.awt.Graphics;<br>           import java.applet.Applet;<br>           public class HelloWorld extends Applet{<br>            String s;<br>           public void init(){<br>            s=&quot;Hello World!&quot;;<br>           }<br>           public void paint(Graphics g){<br>            g.drawString(s,25,25);<br>           }<br>          }<br>        </p>        <p><br>          2<br>           class yanghui<br>           {<br>           public static void main (String args[])<br>           {<br>            int i,j;<br>            int yhlevel=10;<br>            int yanghui[][];<br>            System.out.println(&quot;杨晖三角形:&quot;);<br>          <br>            yanghui=new int[yhlevel][];<br>            for(i=0;i&lt;yanghui.length;i++)<br>             yanghui[i]=new int[i+1];<br>          <br>             yanghui[0][0]=1;<br>            for (i=1; i&lt;yanghui.length;i++)<br>            {<br>            yanghui[i][0]=1;<br>            for(j=1;j&lt;yanghui[i].length-1;j++)<br>             yanghui[i][j]=yanghui[i-1][j-1]+yanghui[i-1][j];<br>             yanghui[i][yanghui[i].length-1]=1;<br>            }</p>        <p>   for (i=0; i&lt;yanghui.length;i++)<br>            {<br>             for(j=0;j&lt;yanghui[i].length;j++)<br>             System.out.print(yanghui[i][j]+&quot; &quot;);<br>             System.out.println();<br>             }<br>            }<br>           } </p>        <p>输出结果是:<br>          杨晖三角形:<br>          1 <br>          1 1 <br>          1 2 1 <br>          1 3 3 1 <br>          1 4 6 4 1 <br>          1 5 10 10 5 1 <br>          1 6 15 20 15 6 1 <br>          1 7 21 35 35 21 7 1 <br>          1 8 28 56 70 56 28 8 1 <br>          1 9 36 84 126 126 84 36 9 1<br>          <br>          3<br>           import java.io.*;<br>           public class MemoController{<br>            FileOutputStream fos;<br>            OutputStreamWriter osw;<br>            BufferedWriter bw;<br>          <br>           public MemoController(){<br>            try{<br>              fos=new FileOutputStream(&quot;memo.txt&quot;,true); <br>              osw=new OutputStreamWriter(fos);<br>              bw=new BufferedWriter(osw);<br>              }catch(FileNotFoundException e){};<br>            }<br>        </p>        <p> <br>           public synchronized void append(String s){<br>            try{<br>              bw.write(s,0,s.length()); <br>              bw.flush();<br>              bw.close();<br>              osw.close();<br>              fos.close();<br>              }catch(IOException e){}<br>            }</p>        <p> <br>           public static void main(String args[]){<br>            MemoController mmc=new MemoController();<br>            mmc.append(&quot;I am xubin &quot;);<br>            }<br>          <br>           }<br>          <br>          4<br>           import java.io.*; <br>           class Phones <br>           {<br>            static FileOutputStream fos;<br>            public static final int lineLength = 81;<br>            public static void main(String args[]) throws IOException<br>            {<br>             byte[] phone = new byte[lineLength];<br>             byte[] name = new byte[lineLength];<br>             int I;<br>             try <br>             {<br>              fos = new FileOutputStream(&quot;phone.numbers&quot;);<br>            }<br>             catch(FileNotFoundException e)<br>             { }<br>             while (true)<br>             {<br>              System.err.println(&quot;Enter a name (enter 'done' to quit)&quot;);<br>              readLine(name);<br>              if (&quot;done&quot;.equalsIgnoreCase(new String(name,0,0,4)))<br>              {<br>               break; <br>              }<br>              System.err.println(&quot;Enter the phone number&quot;); <br>              readLine(phone);<br>              for (int i=0;phone[i]!= 0;i++) <br>             {<br>              fos.write(phone[i]);<br>             }<br>              fos.write(',');<br>              for (int i=0;name[i]!= 0;i++)<br>             {<br>              fos.write(name[i]); <br>             }<br>              fos.write('\n');<br>             }<br>              fos.close();<br>             } </p>        <p>    private static void readLine(byte line[]) throws IOException<br>            { <br>             int i=0,b=0; <br>             while ((i&lt;lineLength-1)&amp;&amp;((b=System.in.read())!='\n'))<br>             {<br>              line[i++] = (byte)b;<br>             } <br>              line[i]=(byte) 0;<br>             } <br>            }        </p>        <p>        </p>        <p>          <!--czp-wenda-daan-->                     </p>      </td>  </tr></table>  </center></body></html>

⌨️ 快捷键说明

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