James
James

Reputation: 85

Storeing a users input as a string in JAVA

Firstly I am very new to JAVA, so I apoligise if I am not quick to pickup on something.

In the example below how could I store the user's input to a string as well as return it?

    Scanner inputme = new Scanner(System.in);
    System.out.println(inputme.nextLine());

I was thinking something along the lines of:

inputme.WritetoString(thestringname);

Upvotes: 0

Views: 91

Answers (1)

Jean Logeart
Jean Logeart

Reputation: 53829

Simply use an intermediate variable:

Scanner inputme = new Scanner(System.in);
String line = inputme.nextLine();
// Do whatever in between
System.out.println(line);

Then the line variable is a String containing... the line :)

Upvotes: 2

Related Questions