展开全部
package test;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class InputTest {
public static void main(String[] args) {
32313133353236313431303231363533e78988e69d8331333363393663Scanner in = new Scanner(System.in);
String line = null;
List persons = new ArrayList();
int times = 0;
while(times <= 3){
line = in.nextLine();
if(null == line || "".equals(line)){
continue;
}
if("q".equalsIgnoreCase(line)){
break;
}
if(line.split(",").length != 3){
System.out.println("提供的信息不正确,请按照\"姓名,电话,地址\"格式提供。");
continue;
}
persons.add(new Person(line.split(",")));
}
for(Person p : persons){
System.out.println(p.toString());
}
}
}
/**
* 实体类
*/
class Person{
private String name; //姓名
private String phone; //电话
private String address; //地址
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Person(String name, String phone, String address) {
super();
this.name = name;
this.phone = phone;
this.address = address;
}
public Person(String... person) {
super();
this.name = person[0];
this.phone = person[1];
this.address = person[2];
}
@Override
public String toString() {
return String.format("姓名:%s, 电话:%s, 地址:%s", name, phone, address);
}
}