javaString类应用案列,一个简单的登录系统
import java.util.Scanner;
public class login {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 3; i++) {
System.out.print("请输入用户名:");
String username = sc.next();
System.out.print("请输入密码:");
String password = sc.next();
if(login(username,password)){
System.out.println("登陆成功!");
return;
}
System.out.println("账号密码错误,请重新输入!(还剩"+(2-i)+"次机会)");
}
System.out.println("bye");
}
public static boolean login(String username, String password){
return username.equals("zeyu") && password.equals("123456");
}
}