如何在线输出答案\uJava

如何在线输出答案\uJava,java,Java,我试图让用户在下一行的输入和输出看起来像这样 __u_a 注**在此之前,他们会选择字符串长度,但我现在不太担心。只是想弄清楚如何将输入转化为输出 以下是我目前的代码: while (!userCorrect) { Scanner input = new Scanner(System.in); System.out.print("Guessing (round " + roundNumber + "): Choosing your letter from

我试图让用户在下一行的输入和输出看起来像这样

__u_a

注**在此之前,他们会选择字符串长度,但我现在不太担心。只是想弄清楚如何将输入转化为输出

以下是我目前的代码:

    while (!userCorrect) {
        Scanner input = new Scanner(System.in);
        System.out.print("Guessing (round " + roundNumber + "): Choosing your letter from a-z: ");
            String letter = input.nextLine();
            for (int i=0; i<letter.length(); i++){ //this is where I'm getting lost
                System.out.println("_" + letter.length());
            }
            if (letter.length () > 1) { //code will print an error if the user selects more than 1 character
            System.out.println("You should not enter more than 1 character");
                }
            else {
            System.out.println("end (round " + roundNumber + ")");
            roundNumber++; 
            }
while(!userCorrect){
扫描仪输入=新扫描仪(System.in);
System.out.print(“猜(圆“+roundNumber+”):从a-z中选择字母:”;
字符串字母=input.nextLine();
对于(inti=0;i试试这个

while (!userCorrect) {
        //Scanner input = new Scanner(System.in);
        System.out.print("Guessing (round " + roundNumber + "): Choosing your letter from a-z: ");
        char letter=0;
        try
        {
             letter=System.in.read();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        //String letter = input.nextLine();
        for (int i=0; i < your_answer_string_length; i++)
        {
            //this is where I'm getting lost
            System.out.print("_");
        }
        System.out.println(letter);
        System.out.println("end (round " + roundNumber + ")");
        roundNumber++; 
    }
while(!userCorrect){
//扫描仪输入=新扫描仪(System.in);
System.out.print(“猜(圆“+roundNumber+”):从a-z中选择字母:”;
字符字母=0;
尝试
{
字母=System.in.read();
}
捕获(IOE异常)
{
e、 printStackTrace();
}
//字符串字母=input.nextLine();
for(int i=0;i

这就是你想要的吗?

检查这个问题:基本上你必须阅读输入而不显示它,然后手动移动光标。有一些库可以这样做。请向我显示所需输出的更多详细信息,例如。我猜不出你想要什么。你正在制作一个刽子手游戏吗?不,不,我正在尝试制作一个包含rand的猜谜游戏om字符,用户需要猜字符串HI,谢谢您的输入。它输出用户响应,但如果用户选择的字符超过1个,我希望它不输出,并且我希望它输出我的错误。您认为如果我将for循环放在if语句中,可以吗?@Gaetano您不必显示任何错误消息因为systrm.in.read()将自动阻止用户输入多个。谢谢!我想我已经找到了解决这个问题的方法。感谢您的帮助!