编辑: 戴静菡 | 2019-07-16 |
2、用输入/输出写一个程序,让用户输入一些姓名和电话号码.每一个姓名和号码将加在文件F1.TXT里.用户输入 done 来告诉系统整个列表已输入完毕.如果用户输入完整个列表,程序将创建一个输出文件并显示或打印出来.格式如: Tom 123-456-7890,Peggy 234-5678,Marc 234-5678, Ron 876-4321,Beth&
Brian 33.1.42.45.70 1.填空题
1、java
2、Test;
Applet;
Runable;
Test.java
3、main
4、Java Applet
5、120 2.选择题
1、D
2、C
3、A、B、E
4、B
5、A、B
6、D
7、A
8、B
9、D
10、D 3.编程题 1) public class TestSplitString { private String str;
private int byteNum;
public TestSplitString(String str, int byteNum) { this.str = str;
this.byteNum = byteNum;
} //截取字符串的函数(只要写出这个函数就可以) public void splitString() { byte bt[] = str.getBytes();
System.out.println( Length of this String ===>
+ bt.length);
if (byteNum >
1) { if (bt[byteNum] <
0) { String substrx = new String(bt, 0, --byteNum);
System.out.println(substrx);
} else { String substrex = new String(bt, 0, byteNum);
System.out.println(substrex);
} } else { if (byteNum == 1) { if (bt[byteNum] <
0) { String substr1 = new String(bt, 0, ++byteNum);
System.out.println(substr1);
} else { String subStr2 = new String(bt, 0, byteNum);
System.out.println(subStr2);
} } else { System.out.println( 输入错误!!!请输入大于零的整数: );
} } } //程序内测试方法 public static void main(String[] args) { TestSplitString tss = new TestSplitString( David大卫David , 8);
tss.splitString();
} }
2、public class Test3 { public static void main(String[] args) throws IOException { String name, phoneNumber;
BufferedReader reader1 = new BufferedReader(new InputStreamReader(System.in));
FileWriter file = new FileWriter( E:/F1.txt );
while (true) { System.out.println( Please input Name: );
name = reader1.readLine();
if (!name.equals( done )) { file.write(name);
file.write( );
} else break;
System.out.println( Please input PhoneNumber: );
phoneNumber = reader1.readLi........