填空题
[说明]
用输入/输出写一个程序,让用户输入一些姓名和电话号码。每一个姓名和号码将加在文件里。用户通过点“Done”按钮来告诉系统整个列表已输入完毕。 如果用户输入完整的列表,程序将创建一个输出文件并显示或打印出来。格式如:555,1212,Tom 123-456-7890,Peggy L.234-5678,Marc 234-5678,Ron 876-4321,Beth&Brian 33.1.42.45.70,Jean-Marc。
[Java 代码]
import java. io.*;
class Phones
{
statlc FileOutputStream fos;
public static final int lineLength =81;
public static void main (String args []) throws IOExeption
{
byte [] phone=new byte [lineLength];
byte [] name=new byte [lineLength];
int i;
try
{
fos= new FileOutputStream ("phone. numbers");
}
catch (FileNotFoundException e)
while (true)
{
{{U}}(1) {{/U}}("Enter a name (enter 'done' to quit)");
{{U}}(2) {{/U}} (name);
if ("done". equalsIgnoteCase (new String (name,0,0,4)))
{
break;
}
System.err.println ("Enter the phone number");
readLine (phone);
for (int i=0;phone [i]!=0;i++)
{
{{U}}(3) {{/U}};
}
fos.write (',');
for (int i=0{{U}} (4) {{/U}};i++)
{
fos. write (name [i]);
}
fos. write ('/n');
}
fos. close();
}
private static void readLine (byte line []) throws IOException
{
int i=0,b=0;
while ((i<{{U}} (5) {{/U}})&& ((b=System.in.read ())!='/n'))
{
line[i++] = ( byte ) b;
}
line[i]= ( byte ) 0;
}
}
【正确答案】
1、(1)System. err. println (2) readLine
【答案解析】(3) fos. write(phone[i]) (4) name[i]!=0
(5) lineLength-1