java 开发实战经典 练习题 第12章 第7题 完成系统登录程序 从命令行输入用户名和密码

来源:互联网 发布:仙侠世界大网络下载 编辑:程序博客网 时间:2024/06/08 16:08
import java.util.Scanner;class LoginOperate{public void check(){String args[] = null;boolean flag = true;int errCount = 0;System.out.println("Please enter usr and pwd : ");Scanner scan = new Scanner(System.in);while(flag){if(errCount == 3){System.out.println("Input error usr or pwd 3 times , system exit ! ");break;}scan.useDelimiter("\n");String loginStr = scan.next();args = loginStr.split("\\s");String username = null;String password = null;if(args.length == 2){username = args[0];password = args[1];if("mldn".equals(username) && "hello".equals(password)){System.out.println("Login successfully,welcome " + username + " back!");break;}else {System.out.println("usr or pwd error");errCount++;continue;}}else if(args.length == 1){username = args[0];System.out.println("Please enter pwd");errCount++;continue;}else{if(args.length == 0){System.out.println("Please retype usr and pwd!");errCount++;continue;}}scan.close();System.out.println("errorCounts = " + errCount);}}}public class TestLoginOperate {public static void main(String[] args) {LoginOperate loginOpera = new LoginOperate();loginOpera.check();}}

阅读全文
0 0
原创粉丝点击