資料庫系統作業要求先自己建一個txt檔案,每行12位數字,前六位是用戶名,后六位是相應的密碼,要用java創建一個用戶登陸界面驗證密碼是否正確。一點不會java,求完整程式包
uj5u.com熱心網友回復:
String account = "111111";String password = "111111";
Map<String, String> map = new HashMap<String , String>();
String path = "D:\\test.txt";
File file = new File(path);
BufferedReader bReader = new BufferedReader(new FileReader(file));
String string = "";
String pc [] = null;
String key = "";
String value = "";
while ((string = bReader.readLine()) != null) {
pc = string.split(",");
key = pc[0];
value = pc[1];
map.put(key, value);
}
Set<String> keySet = map.keySet();
for (String string2 : keySet) {
System.out.println(string2);//賬號
System.out.println(map.get(string2));//密碼
if (account .equals(string2) && password.equals(map.get(string2))) {
System.out.println("賬號密碼正確");
break;
}else {
System.out.println("賬號密碼錯誤");
}
}
bReader.close();
//txt文本,密碼和賬號之間用英文逗號分隔
uj5u.com熱心網友回復:
String account = "111111";String password = "111111";
Map<String, String> map = new HashMap<String , String>();
String path = "D:\\test.txt";
File file = new File(path);
BufferedReader bReader = new BufferedReader(new FileReader(file));
String string = "";
String pc [] = null;
String key = "";
String value = "";
@SuppressWarnings("unused")
boolean result = false;
while ((string = bReader.readLine()) != null) {
pc = string.split(",");
key = pc[0];
value = pc[1];
map.put(key, value);
}
Set<String> keySet = map.keySet();
for (String string2 : keySet) {
System.out.println(string2);//賬號
System.out.println(map.get(string2));//密碼
if (account .equals(string2) && password.equals(map.get(string2))) {
result = true;
break;
}
}
if (result = false) {
System.out.println("密碼錯誤");
}else {
System.out.println("賬號密碼正確");
}
bReader.close();
剛那個有點問題,改了一下
uj5u.com熱心網友回復:



uj5u.com熱心網友回復:
學習了。非常棒。uj5u.com熱心網友回復:
親 我不管輸不輸密碼都直接成功??連比對都沒比uj5u.com熱心網友回復:
3#比較有問題==比較
= 賦值
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/46167.html
標籤:Java SE
上一篇:求救大神們這個編程怎么做
