//控制台登录.倒包.
import java.util.Scanner;
class Demo
{
public static void main(String[]args)
{
//定义登录的密码还有名字.
String Uname = "hellokitty";
String Upwb = "26624";
//系统给出了三次登录的机会.
int count = 3 ;
while(true){
//控制台输入.
Scanner sc = new Scanner(System.in);
//提示输入;
System.out.println("请输入登录的名字:");
//接收登录的名字.
String Youname = sc.next();
System.out.println("请输入登录密码:");
String Youpwb = sc.next();
//判断是否与系统的一样.
if(Youname.equals(Uname)&& Youpwb.equals(Upwb)){
//如果一样那就登录成功.
System.out.println("登录成功!");
break;
}else{
count--;
System.out.println("登录的名字或者密码错误,你还有"+count+"次机会");
break;
}
}
}
}
|
|