A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© java程序猿 中级黑马   /  2016-9-16 21:43  /  537 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

* map中有如下数据(电话号=套餐价格)
* [13265477888=168,15241698745=11,13699989898=20,1898686666=120]
* 在ip为127.0.0.1数据库名为stdb
* ,连接数据库的用户名和密码为:admin和123456中有一个numinfo表相关字段为(id,iphonenum,tomoney)(15分)
* (1)将map中的手机号码取出来打印到控制台上(3分)
* (2)判断map中所有的手机号在numinfo表中是否存在存在则输出"该主机已登录"如果不存在将该号码及对应的套餐价格存入到numinfo表中.(12分)
* (map中的数据不需要修改)


[AppleScript] 纯文本查看 复制代码
public class StrongTest2 {
	public static void main(String[] args) {
		Map<String, Integer> map = new HashMap<>();
		map.put("13265477888", 168);
		map.put("15241698745", 11);
		map.put("13699989898", 20);
		map.put("1898686666", 120);

		for (String str : map.keySet()) {
			System.out.println(str + "=" + map.get(str));
		}
		stdb db = null;
		try {
			db = new stdb("admin","123456");
		}catch(Exception e) {
			db = null;
			e.printStackTrace();
		}
		
		String key = "15241698745";
		
		if(db != null) {
			if(db.getMap().containsKey(key)) {
				System.out.println("该主机已登录");
			}else {
				db.getMap().put(key, map.get(key));
			}
		}
		
		System.out.println("数据库中存在以下号码套餐");
		for(String str :db.getMap().keySet()) {
			System.out.println(str + "=" + db.getMap().get(str));
		}
	}
}

// 模拟数据库
class stdb {
	private static Map<String, Integer> map = new HashMap<>();// 模拟numinfo表
	public static final String username = "admin";
	public static final String password = "123456";

	public Map<String,Integer> getMap() {
		map.put("13265477888", 168);
		return map;
	}

	public static String getUsername() {
		return username;
	}

	public static String getPassword() {
		return password;
	}

	public stdb(String un, String pw) throws Exception {
		if(!username.equals(un) || !password.equals(pw)) {
			System.out.println("用户名或密码输入错误");
			throw new Exception("用户名或密码输入错误");
		}
		
	}
	
	private stdb() {}

}





不喜勿喷,小菜制作,大神谅解

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马