public static void main10(String[] args) { Scanner s=new Scanner(System.in); Random rnd=new Random(); int random=rnd.nextInt(100)+1; while(true){ System.out.println("请输入你要猜的数字:"); int n=s.nextInt(); if(n<random){ System.out.println("猜小了"); } else if(n==random){ System.out.println("猜对了"); break; } else{ System.out.println("猜大了"); } } } public static void main(String[] args) { int count=3; Scanner s=new Scanner(System.in); String str="123"; while(count!=0){ System.out.println("请输入你的密码:"); String password=s.nextLine(); if(password.equals(str)){ System.out.println("登陆成功!"); break; } else{ count--; System.out.println("你还有"+count+"次机会!"); } } }