List<User> list=null
陆雹 public CustomerBiz() {
list=new ArrayList<User>()
}
private void addName(String name) {
User user=new User(name)
list.add(user)
}
private void showNames() {
System.out.println("***************************************")
System.out.println("***************************************")
for (int i = 0 i < list.size() i++) {
System.out.print(list.get(i).getName()+" ")
if(i%4==0 && i>0)
System.out.println()
}
}
public static 铅纤void main(String[] args) {
CustomerBiz customerBiz=new CustomerBiz()
doInput(customerBiz)
}
public static void doInput(CustomerBiz customerBiz){
早激帆 String name=""
Scanner in=new Scanner(System.in)
System.out.println("请输入客户姓名:")
name=in.next()
if(name.equals("")) {
System.out.println("请重新输入客户姓名:")
name=in.next()
}
customerBiz.addName(name)
System.out.println("继续输入吗?y/n")
String tag=in.next()
if(tag.equals("y")){
doInput(customerBiz)
}else{
customerBiz.showNames()
}
}
}
class User{
String name
public String getName() {
return name
}
public void setName(String name) {
this.name = name
}
public User(String name) {
this.name=name
}
}
package chonggou1public class Clum {
private String name
public Clum(){
}
public String getName() {
return name
}
public void setName(String name) {
this.name = name
}
public void toShow() {
if(name==null){
System.out.println("请烂运高碰先添加姓名")
return
}
System.out.println(this.name)
}
public static void main(String[] args) {
Clum c=new Clum()//创建客服
c.setName("zs")//添加姓名
c.toShow()//饥念梁显示客服
Clum c2=new Clum()//创建客服
c2.toShow()//显示客服
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)