Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 正在跳过System.out.println()_Java - Fatal编程技术网

Java 正在跳过System.out.println()

Java 正在跳过System.out.println(),java,Java,在第二个for循环没有出现之后,我的提示“请输入您的ID”,它直接转到“请输入您的密码”。它还跳过了从登录提示到密码提示的许多代码。如果你对它为什么会这样有任何想法,请与我分享,谢谢 public void main(String[] args){ Accounts Accounts = new Accounts(); Scanner kb = new Scanner(System.in); System.out.print("Please create a log

在第二个for循环没有出现之后,我的提示“请输入您的ID”,它直接转到“请输入您的密码”。它还跳过了从登录提示到密码提示的许多代码。如果你对它为什么会这样有任何想法,请与我分享,谢谢

public void main(String[] args){

    Accounts Accounts = new Accounts();

    Scanner kb = new Scanner(System.in);

    System.out.print("Please create a login ID and hit \"ENTER\": ");
    Login = kb.nextLine();

    for(;;){
        if(!Accounts.isTaken(Login)){
            System.out.print("Please create a password and hit \"ENTER\": ");
            PW = kb.nextLine();
            if(Accounts.validPW(PW)){
                Accounts.createAccount(Login, PW);
                break;
            }
        }
    }

    System.out.print("Do you wish to Log in ? (Y/N): ");
    String response = kb.nextLine();
    if((response=="y")||(response=="Y")){
        for(;;){
           //Not Being Shown
            System.out.println("Please enter your ID: "); // ?????? Where are you?????
            Login = kb.nextLine();
            Accounts.login(Login);
            //Goes straight here
            System.out.print("Please enter your Password: ");
            if ((Accounts.isValid(Login))&&(Accounts.checkAuth(kb.nextLine()))){
                break;
            }
            else{
                System.out.println("Invalid Login-Password!");
            }
        }
    }
    System.out.println("Please enter your Password: ");
    System.out.println("LOGIN AUTHORIZED: "+Accounts.checkAuth(kb.nextLine()));
 }
而不是

(response=="y")||(response=="Y")
使用


您正在使用
==
运算符检查字符串是否相等。使用
equals()方法

=
操作员:

  • 对于基元变量,检查两个基元是否具有相同的值
  • 对于对象:检查两个引用变量是否指向(引用)同一对象
  • equals()方法

  • 检查两个对象是否完全相等

    如果((响应==“y”)| |(响应==“y”)){

  • 应该是

    if((response.equals("y"))||(response.equals("Y"))){
    
    甚至更好

    if((response.equalsIgnoreCase("y"))){
    

    由于java是基于引用的,所以响应的id与“y”不同

     response.equals("y")
    

    可能重复使用
    String.equals()
    ,而不是
    =
    。不要将
    用于(;;)
    循环——我们有while循环用于此…最好编写
    while(true)
    而不是
    用于(;;)
    @Charles。不客气。祝你好运。顺便说一句,如果回答有帮助,请不要忘记接受它。
     response.equals("y")