1

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.

1
  • you mean you want the input from user..? Commented Dec 31, 2014 at 12:50

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.