本文实例为大家分享了Java通讯录系统的具体代码,供大家参考,具体内容如下
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
import java.util.Scanner; class Person { String name; String number; } class connect { Person a[]; int number; public connect() { a= new Person[ 100 ]; number= 0 ; } public String add(String name,String number) { if (number == "0" ) System.out.println( "请先添加联系人!" ); if ( this .number> 99 ) return "添加失败" ; a[ this .number]= new Person(); a[ this .number].name=name; a[ this .number].number=number; this .number++; return "添加成功" ; } public Person seek(String name) { if (number == 0 ) System.out.println( "请先添加联系人!" ); for ( int i= 0 ;i<number;i++) { if ((a[i].name).equals(name)) { System.out.println( "联系人: " +a[i].name+ " 电话:" +a[i].number); return a[i]; } } return null ; } public void look() { if (number == 0 ) System.out.println( "请先添加联系人!" ); for ( int i= 0 ;i<number;i++) { System.out.println( "联系人 " +a[i].name+ " 电话 " +a[i].number); } } public String delete(String name) { if (number == 0 ) System.out.println( "请先添加联系人:" ); for ( int i= 0 ;i<number;i++) { if ((a[i].name).equals(name)) { a[i]=a[ this .number- 1 ]; number=number- 1 ; return "删除成功" ; } } return "删除失败" ; } } public class text1 { public static void main(String[]args) { Scanner sc= new Scanner(System.in); Scanner input = new Scanner(System.in); System.out.println( "\t\t\t欢迎使用通讯录系统\n" ); System.out.println( "\t\t\t1.创建用户\n\n\t\t\t2.退出\n" ); System.out.println( "____________________________________________________________________\n\n" ); System.out.print( "请选择相应选项:" ); int num2 = sc.nextInt(); while (num2!= 2 ) { switch (num2) { case 1 : { connect c = new connect(); System.out.println( "\t\t\t1.浏览\n" );System.out.println( "\t\t\t2.查找\n" ); System.out.println( "\t\t\t3.添加\n" );System.out.println( "\t\t\t4.删除\n" ); System.out.println( "\t\t\t5.退出\n" );System.out.println( "请选择相应选项:" ); System.out.println( "输入指令:" ); int num1 = input.nextInt(); switch (num1) { case 1 :c.look(); break ; case 2 : { System.out.println( "输入查找的名字:" ); String n1 = sc.next();c.seek(n1); } break ; case 3 : { System.out.println( "输入要添加的人数:" ); System.out.println( "enter:" ); int s=sc.nextInt(); for ( int i= 0 ;i<s;i++) { System.out.println( "请输入第" +(i+ 1 )+ "个人的名字:" ); String name=sc.next(); String number=sc.next(); c.add(name,number); } } break ; case 4 : { System.out.println( "输入删除的姓名:" ); String n3 = sc.next();c.delete(n3); } break ; default : { System.out.println( "\t\t\t谢谢您的使用\n" ); System.exit( 0 ); } } } break ; case 2 :System.out.println( "\t\t\t谢谢您的使用\n" ); break ; default :System.out.println( "输入有误!" );num2= 2 ; } } } } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:http://blog.csdn.net/lijia111111/article/details/72582653