Tag: 用户输入

java / clojure中的单字符控制台输入

如何从控制台读取单个字符/键而无需按Enter键? Sun的bug数据库中有一个旧条目声称无法在纯java中完成。 我找到了这些方法 JNI JLine [ http://jline.sourceforge.net/] Javacurses [ http://sourceforge.net/projects/javacurses/] 我希望在我的类路径中添加一个magic-readkey.jar ,并编写几行代码,如(def just-hit (com.acme.MagicConsole/read-char)) 。

在selenium webderiver中从IDE / Console获取用户输入

我想从用户输入中获取密钥(发送密钥)我应该如何实现它? driver.findElement(By.xpath(“.//*[@id=’vehicleNum’]”)).sendKeys(“1121”);

Java Homework用户输入问题

我有一个类分配来使用Scanner读取数据。 import java.util.Scanner; public class Project23 { public static void main(String[] args) { // Declarations and instantiations. Scanner scan = new Scanner(System.in); String any = “”; boolean more = false; double purchase = 0.0; // Ask if user would like to run program? System.out.print(“Do you have any purchases? Y/N?: “); // Ready value into string. […]

java打印一个三角形

我正在尝试创建一个程序,用户输入三角形应该多长时间以及它的方向。 我遇到的问题是它在运行后不断向程序添加更多数字。 例如 State the length of the two sides (finish with -1): 5 Should the triangle face down (0) or up(1): 1 * ** *** **** ***** 2 Should the triangle face down (0) or up(1): 1 * ** *** **** ***** ****** ******* 我的代码: import java.util.Scanner; public class Triangel { public static void […]

以编程方式退出应用程序的适当方法是什么?

我正在评估用户输入作为我的应用程序的命令。 如果用户按下Q或q ,然后按Enter键,则应用程序退出并执行终止。 是否有适当的背景或最佳实践如何做到这一点? 我没有任何资源可以发布,或类似的东西。 我应该只使用System.exit(0); ? 有推荐的方法吗? 作为我的第一个方法,我做了这样的事情: while (true){ try{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //Other logic goes here… if (br.readLine().equalsIgnoreCase(“Q”)){ System.exit(0); } } catch (IOException ioe) { System.out.println(“IO error trying to read your selection”); } }

如何在InputMismatchException之后重试输入?

我正在创建一个从用户获取输入的程序。如果用户输入无效命令,我想重新运行输入选项。 像这里只有整数输入是首选,但如果用户输入文本,那么我想捕获exception并重新运行该方法。 我试过这个但是它把我变成了一个无限循环。这是实现这个目标的最好方法。 如果有人帮助我这件事会很棒。 boolean retry = true; while(retry){ try{ //considering response from the user System.out.print(“\nEnter Your Command : “); f_continue = processresponse(scanner.nextInt()); retry = false; }catch(InputMismatchException e){ System.err.println(“\nPlease Input a Valid Command from 1-5 or 0 for Exit”); } }

Java – 将用户输入分配给变量/更改计数器

我对java很新,虽然我对C ++有相当基本的了解。 对于我的任务,我正在计算变化并将其分类为美国货币(即,如果你有105美分,则将其分为1美元和1美分)。 逻辑上我理解如何做到这一点,但我在理解java语法时遇到了一些麻烦。 我很难找到一种方法将用户输入的值分配给我的创建变量。 在C ++中你只需要使用cin,但Java在这方面似乎要复杂得多。 这是我到目前为止的代码: package coinCounter; import KeyboardPackage.Keyboard; import java.util.Scanner; public class helloworld { public static void main(String[] args) { Scanner input new Scanner(System.in); //entire value of money, to be split into dollars, quarters, etc. int money = input.nextInt(); int dollars = 0, quarters = 0, dimes = 0, nickels = […]

LibGdx,如何处理触摸事件?

我是LibGdx新手,并试图使我的iceCream图像可触摸。 我想知道如何设置输入过程(通过触摸屏幕)。 我需要再上一堂课吗? 当我尝试将输入过程实现到我的Prac1类时,JAVA不允许我在不改变类抽象的情况下实现。 具体来说,我喜欢在用户触摸图像时制作它,它会计算触摸次数。 这是我的代码,谢谢你的帮助。 import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; public class Prac1 extends ApplicationAdapter { int w,h,tw,th =0; OrthographicCamera camera; SpriteBatch batch; Texture img; @Override public void create () { w = Gdx.graphics.getWidth(); h = Gdx.graphics.getHeight(); camera = new OrthographicCamera(w, h); camera.position.set(w/2, h/2, 0); camera.update(); batch […]

使用用户输入创建新对象

嗨我正在尝试创建一个程序,以便在用户输入特定对象的新信息时创建新对象。 目前我有这个。 import java.util.Scanner; public class Main { public static void main (String args[]) { String input; Scanner scanner = new Scanner(System.in); do { System.out.println(“Computer Menu”); System.out.println(“1. Add a new Desktop Information”); System.out.println(“2. Add a new Laptop Information”); System.out.println(“3. Display all Computer Information”); System.out.println(“4. Quit”); System.out.print(“Please enter either 1 to 4: “); input =(scanner.nextLine()); if […]

将用户输入字符串转换为大写Java

这可能看起来像一个愚蠢的问题,但经过谷歌的网页,我已经能够找到我想要的答案。 s1.setName(JOptionPane.showInputDialog(“Enter Name: “); 对于上面的代码,我如何将用户输入的数据格式化为所有大写字母? 任何帮助在这里将不胜感激。