public class CustomerBiz {
String[] names=new String[5];
public void addName(String name){
for(int i=0;i<names.length;i++){
if(names[i]==null){
names[i]=name;
break;
}
}
}
public void showName(){
for(int i=0;i<names.length;i++){
System.out.print(names[i]+" ");
}
}
public boolean editName(String oldName,String newName){
boolean find=false;
for(int i=0;i<names.length;i++){
if(names[i].equals(oldName)){
names[i]=newName;
find=true;
break;
}
}
return find;
}
public void shownewName(){
for(int i=0;i<names.length;i++){
System.out.print(names[i]+" ");
}
}
}
import java.util.*;
public class TestCustomer {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
CustomerBiz c=new CustomerBiz();
for(int i=0; i<5; i++){
System.out.print("请输入客户姓名: ");
String name=input.next();
c.addName(name);
}
System.out.println("****************************");
System.out.println("\t客户姓名列表");
System.out.println("****************************");
c.showName();
System.out.println();
System.out.print("请输入要修改的客户姓名: ");
String s=input.next();
System.out.print("请输入新的客户姓名: ");
String d=input.next();
if(c.editName(s, d)){
System.out.println("找到并修改成功!");
}else{
System.out.println("没找到,抱歉.");
}
System.out.println("****************************");
System.out.println("\t客户姓名列表");
System.out.println("****************************");
c.shownewName();
}
}
转载请注明原文地址: https://ju.6miu.com/read-1126107.html