Skip to content

Issue with reading user input #14

@Poonna

Description

@Poonna

Hi again,

I've been trying to get user input on Jupyter Notebook without success. I'm not sure what the problem is, but the code here:

import java.util.Scanner;

Scanner input = new Scanner(System.in);
String s = input.next();
System.out.println(s);

produced this error:

---------------------------------------------------------------------------
java.util.NoSuchElementException: 
	at java.base/java.util.Scanner.throwFor(Scanner.java:858)
	at java.base/java.util.Scanner.next(Scanner.java:1381)
	at .(#19:1)

If I used input.nextLine() instead, I got a No line found error:

---------------------------------------------------------------------------
java.util.NoSuchElementException: No line found
	at java.base/java.util.Scanner.nextLine(Scanner.java:1554)
	at .(#19:1)

I tried switching to BufferedReader:

import java.io.BufferedReader;
import java.io.InputStreamReader;

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String s = reader.readLine();
System.out.println(s);

which resulted in:

null

I wonder if there's a way to get this to work. Please let me know if I could be of any help.

Thanks,
Poonna

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions