简体   繁体   中英

How to insert value in console of eclipse using java code

I want to enter value in console at run-time (during execution), rather than hard code it manually. I have following code:

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();   

Here I want to insert the value of 'pinNum' in console and proceed with the next steps.Please suggest regarding it.

If you want to get the input from the user from console use java.util.Scanner class

 System.out.println("Enter a number: ")
 Scanner sc = new Scanner(System.in);
 int i = sc.nextInt();
 System.out.println("The number is: "+i);

The above code will help you to get the input from console

For more on Scanner refer Oracle docs

Basically System.in is The standard input stream .this stream corresponds to keyboard input or another input source specified by the host environment or user. so you can use it in some of the java IO API.as @abhishek told for Scanner you can also use below code.

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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