Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8167461

jshell tool: Scanner#next() hangs tool

XMLWordPrintable

    • b142
    • Verified

      Recent fixes have addressed program input in the jshell tool. So now:

          System.in.read()

      works.

      However, as reported by Paul Deitel --

      ...
      For example, should I be able to use a Scanner object?

      The following creates one
      Scanner input = new Scanner(System.in);

      But if I then type
      int x = input.nextInt();

      it appears to execute the statement and wait for input, but I can’t get that input to work. After typing a number and pressing Enter, I just get a blank line. I then have to type Control C to terminate the input. At this point JShell shows

      x ==>

      and evaluating x then gives 0.

      One of the most basic things a new programming student will do is use command-line input statements. I realize they can simply say something like

      int x = 32;

      but once we show them JShell, they’re sure to try out the above input capability too.

      Best,
      Paul



            jlahoda Jan Lahoda
            rfield Robert Field (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: