开发者

Storeing a users input as a string in JAVA

开发者 https://www.devze.com 2023-03-27 22:09 出处:网络
Firstly I am very new to JAVA, so I apoligise if I am not quick to pickup on something. In the example below h开发者_运维问答ow could I store the user\'s input to a string as well as return it?

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

In the example below h开发者_运维问答ow 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);


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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消