0

I have a code that takes input using scanner but the number of input is not defined. How to run the code in Netbeans?

The code is as follows:

Scanner scan = new Scanner(System.in);
while(scan.hasNextLine()){
    // print the token
    System.out.println(scan.next());
}
scan.close();

When I run the code, it is only taking input and no further processing is done.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
Prakhar Singh
  • 81
  • 1
  • 1
  • 6
  • In your code, You are just printing the input to output stream. what type of processing do you want? – Yohannes Gebremariam Feb 28 '17 at 18:33
  • For the record: this has **nothing** to do with the IDE that you are using. No need to put a netbeans tag on a pure java question! – GhostCat Feb 28 '17 at 18:41
  • Possible duplicate of [How to terminate Scanner when input is complete?](http://stackoverflow.com/questions/16206813/how-to-terminate-scanner-when-input-is-complete) – Patrick Parker Feb 28 '17 at 18:50

2 Answers2

1

I assume you want to take input, then print it?

Put in something like:

String s = scan.next(); 

before the while loop.

achAmháin
  • 4,176
  • 4
  • 17
  • 40
0

Not sure what your input looks like, so maybe try changing

hasNextLine()

to just

hasNext()
Logan L.
  • 85
  • 7