填空题 [说明]
用输入/输出写一个程序,让用户输入一些姓名和电话号码。每一个姓名和号码将加在文件里。用户通过点“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)
{
__ 1__ ("Enter a name (enter "done" to quit)");
__ 2__ (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++)
{
__ 3__
}
fos.write (",");
for (int i=0 __ 4__ ;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< __ 5__ )&& ((b=System.in.read ())!="\n"))
{
line[i++] = ( byte ) b;
}
line[i]= ( byte ) 0;
}
}
【正确答案】
【答案解析】System. err. println readLine
fos. write(phone[i]) name[i]!=0
lineLength-1