求救啊

aaaabbbccd9876 2012-10-08 01:56:01
public void text(){
String s = null;
try{
FileReader fr = new FileReader("1.txt");
int b=0;

char[]buf = new char[1024];
while((b=fr.read(buf))!=-1)
s = new String(buf,0,b);
// System.out.println(new String(buf,0,b));
}
catch(IOException e1){}
String a = " +";
String sa[] = s.split(a);
System.out.println(sa[0]+"....."+sa[4]);
String s1 = text1.getText();
String s2 = text2.getText();
// String a1 ="[a-z]{6,10}";
String a2 ="\\w{6,10}";
// boolean flag1 = s1.matches(a1);
boolean flag2 = s2.matches(a2);
System.out.println(s1.equals(sa[0])&&s2.equals(sa[4]));
// if(!flag1)
// JOptionPane.showMessageDialog(this,"您输入了非法字符","警告提示框",
// JOptionPane.WARNING_MESSAGE);
if(!flag2)
JOptionPane.showMessageDialog(this,"密码输入错误!","警告提示框",
JOptionPane.WARNING_MESSAGE);
else if((s1.equals(sa[0])&&s2.equals(sa[4])))
new hello();
else
JOptionPane.showMessageDialog(this,"密码或账号输入错误!","警告提示框",
JOptionPane.WARNING_MESSAGE);


}

为什么else if((s1.equals(sa[0])&&s2.equals(sa[4])))
这儿比较后我在界面的text2里乱输入密码,new hello();
任然可以执行
...全文
106 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lost_guy_in_scut 2012-10-08
  • 打赏
  • 举报
回复
1楼是正确的。
s_1051125617 2012-10-08
  • 打赏
  • 举报
回复
你把s1,s2,sa[0]和sa[4]输出来看看,看看是不是对应相等。
aaaabbbccd9876 2012-10-08
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
去掉一对括号改成,因为你把两个逻辑整个扩在一起放if了。
else if (s1.equals(sa[0])&&s2.equals(sa[4]))
[/Quote]我觉得不是这个原因,我照你说的改了,还是不对(输入对应的账号和密码就是不对,执行的是else下面的语句)
  • 打赏
  • 举报
回复
一楼是对的,你试试先把
  • 打赏
  • 举报
回复
去掉一对括号改成,因为你把两个逻辑整个扩在一起放if了。
else if (s1.equals(sa[0])&&s2.equals(sa[4]))

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧