import java.util.Scanner; public class Guessnumber2 { public static void main(String[] args) { String usename ="hcw"; int password = 12345; for (int i = 0; i < 5; i++) { Scanner sc = new Scanner(System.in); System.out.println("请输入账户名"); String gessname = sc.nextLine(); System.out.println("请输入密码"); int gesspassword = sc.nextInt(); if(gessname.equals(usename)&&gesspassword==password){ System.out.println("输入正确,开始玩猜字游戏"); GuessNumber.guessNumber(); break; } else{ if((4-i)==0){ System.out.println("密码超过5次错误,被锁住了"); break;} else{ System.out.println("你还有"+(4-i)+"次机会"); } } } } }
|