Java:使用Scanner.nextLine()上的默认值填充Scanner。 [英] Java: populating Scanner with default value on Scanner.nextLine();

查看:210
本文介绍了Java:使用Scanner.nextLine()上的默认值填充Scanner。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个运行循环并不断要求用户输入的Java程序。该程序然后对字符串执行一堆操作,并要求另一个字符串并重复。

I am writing a java program that runs a loop and keeps asking the user for input. The program then does a bunch of things with the string, and asks for another string and repeats.

问题是许多字符串非常相似,所以我想使用循环中最后一次的输入来填充提示。例如:如果用户输入如下值:

The issue is that many strings are very similar, so i would like to populate the prompt with the input from the last time in the loop. For instance: If the user enters a value as follows:

Enter the SKU Number: APE-6603/A

...然后,下次请求SKU时,它将一直等到用户正常按Enter键,在用户输入任何内容之前,请准备好最后一个值:

... Then the next time it asks for an SKU, it will wait till the user presses enter as normal, but be ready with the last value before the user even types anything:

Enter the SKU Number: APE-6603/A

...用户可以非常快速地进行简单的更改,例如将/ A替换为/ B,然后按Enter!如果保存用户输入的字符串称为 lookFor,是否可以用Java中的该值填充提示?

... And the user can make simple changes very fast like replace the /A with /B and press enter! If the string that holds the user input is called "lookFor", is there a way to populate the prompt with this value in Java? It would be VERY useful!

谢谢!

推荐答案

这个想法与几个人在一起,看来我想要的是不可能的。输入的方法太简单了,不允许出现这样的内容。

After discussing this idea with a few people, it seems that what i want is not possible. The way of input is too simple to allow something like this.

我唯一可能的解决方案是不要从IDE中运行它。我可以选择使用我的应用程序,也可以将应用程序更改为基于GUI的小程序。如rchirino所建议,从控制台运行将打开 Press up选项,并使用GUI将输入的值放在该位置以供以后编辑。

My only possible solutions involve not running this from my IDE. I can either elect to use my application, or change the application into a GUI based applet. Running from the console will open up the "Press up" option, as suggested by rchirino, and using a GUI would let the value entered sit there for editing later.

如果任何人都想做我上面发布的内容,答案是 Java无法做到!。抱歉。 :)

If anyone is looking to do what i posted above, the answer is "Java cant do it!". Sorry. :)

这篇关于Java:使用Scanner.nextLine()上的默认值填充Scanner。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆