package com.String; import java.util.Scanner; public class userDemo { public static void main(String[] args) { for (int i=0;i<3;i++) { Scanner sc=new Scanner(System.in); System.out.println("请您输入登录名称:"); String luginName=sc.next(); System.out.println("请您输入密码:"); String passWord=sc.next(); //开始调用登陆方法,判断是否登录成功 boolean rs=login(luginName,passWord); if (rs){ System.out.println("登录成功"); break; }else { System.out.println("登录失败"); } } } //登陆方法,接受用户的登录名和密码,返回认证结果 public static boolean login(String loginName,String passWord){ //准备一份系统正确的登录名和密码 String okLoginName="itheima"; String okPassWord="123456"; //开始正式判断用户是否登录成功 if (okLoginName.equals(loginName) && okPassWord.equals(passWord)){ //登录成功 return true; }else { return false; } } }
标签:userDemo,java,String,package,案例,public From: https://www.cnblogs.com/Karl-hut/p/17438034.html