我想在运行时(执行期间)在控制台中输入值,而不是手动对其进行硬编码。我有以下代码:
System.out.println("Open the following URL and grant access to your account:");
System.out.println(requestToken.getAuthorizationURL());
String authURL=requestToken.getAuthorizationURL();
//Generate a pin number from auth url by login to twitter account.
String pinNum=GenratePIN_LoginTwitter.accessTokenForTwitter(authURL);
System.out.print("Enter the PIN(if aviailable) or just hit enter.[PIN]:");
String pin =br.readLine();
在这里,我想在控制台中插入“pinNum”的值并继续执行后续步骤。请提出相关建议。
最佳答案
如果您想从控制台获取用户的输入,请使用 java.util.Scanner
类
System.out.println("Enter a number: ")
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
System.out.println("The number is: "+i);
上面的代码将帮助您从控制台获取输入
有关扫描器
的更多信息,请参阅 Oracle docs
关于java - 如何使用java代码在eclipse的控制台中插入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27721379/