1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package  上机练习;
 
public  class  A02class {
     String names[] =  new  String[ 30 ];
 
     public  void  showA(String name) {
         for  ( int  i =  0 ; i < names.length; i++) {
             if  (names[i] ==  null ) {
                 names[i] = name;
                 break ;
             }
         }
     }
 
     public  void  showB() {
         System.out.println( "\t客户列表显示" );
         for  ( int  i =  0 ; i < names.length; i++) {
             if  (names[i] !=  null ) {
                 System.out.print(names[i] +  "\t" );
             }
         }
     }
 
     public  boolean  showC(String find) {
         boolean  con =  false ;
         for  ( int  i =  0 ; i < names.length; i++) {
             if  (names[i] !=  null ) {
                 if  (names[i].equals(find)) {
                     con =  true ;
                     break ;
                 }
             }
         }
         return  con;
     }
}
 
 
 
 
 
 
package  上机练习;
 
import  java.util.Scanner;
 
public  class  A02 {
 
     public  static  void  main(String[] args) {
         // TODO Auto-generated method stub
         A02class A02 =  new  A02class();
         Scanner in =  new  Scanner(System.in);
         boolean  con =  true ;
         while  (con) {
             System.out.println( "请输入客户的姓名:" );
             String admin = in.next();
             A02.showA(admin);
             System.out.println( "请输入是否继续:(y / n ):" );
             String choice = in.next();
             if  (choice.equals( "n" )) {
                 con =  false ;
                 break ;
             }
         }
         A02.showB();
         System.out.println( "请输入要查找的客户的姓名:" );
         String find = in.next();
         if  (A02.showC(find)) {
             System.out.println( "有" );
         else  {
             System.out.println( "没有" );
         }
     }
 
}