import java.util.Map
import java.util.Scanner
public class Str {
public static String userName
public static String pass
/**
* @param args
*/
public String toString() {
return "用户名" + this.userName + " 密码:" + this.pass
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in)
System.out.println("请输入用户名:")
userName = input.next()
System.out.println("请输入密码:")
pass = input.next()
Map map = new HashMap()
map.put(userName, pass)
System.out.println("请选择:1.添加用户 2.显示所改兆乱有用户 3.删除指定用户 请选择(1 2 3)")
try {
int v = input.nextInt()
while (v != 1 &&v != 2 &&v != 3) {
System.out.println("请选择:1.添加用户 2.显示所有用户 3.删除指定用户")
v = input.nextInt()
}
if (v == 1) {
System.out.println("核档请输入用户名:")
userName = input.next()
System.out.println("请输入密码:")
pass = input.next()
map.put(userName, pass)
} else if (v == 2) {
System.out.println(map)
} else if (v == 3) {
System.out.println("请输入要删除的用户名猜蠢:")
userName = input.next()
if (map.containsKey(userName))
map.remove(userName)
}
} catch (Exception e) {
e.printStackTrace()
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)