简体   繁体   English

如何让用户输入在 java 中重复我的代码?

[英]How can I let the user input repeat my code in java?

Here is my code so far.到目前为止,这是我的代码。 (this is part of it, it's very long) I can't figure out what's wrong with it. (这是它的一部分,它很长)我无法弄清楚它有什么问题。 I have tried searching for other answers on this website and tried something similar but still don't get it.我曾尝试在此网站上搜索其他答案,并尝试了类似的方法,但仍然不明白。 I am not really understanding how this while loop should work since my code is, as I said, very long.我并不真正理解这个 while 循环应该如何工作,因为正如我所说,我的代码很长。 I just can't figure it out and it's confusing me a lot.我只是想不通,这让我很困惑。 Please help?请帮忙?

 do{
  String retake;

  System.out.println("Would you like to play again? Type in Y for yes or N for no ");

  retake = kbd.nextLine();
  } while ( yes.equalsIgnoreCase("yes"));
 }
}

You are taking user's choice in retake variable so check while condition with retake.您在重拍变量中采用用户的选择,因此请检查重拍条件。 Like below:如下所示:

    // declare retake variable in outer scope
    string retake;
    do{

       //String retake;

    /**
        Put your code logic here!
     */


    System.out.println("Would you like to play again? Type in Y for yes or N for no ");

    retake = kbd.nextLine();
  } while ( retake.equalsIgnoreCase("Y"));
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM