Hi all! I have a basic doubt but I'm stuck with it...
# getting-started
m
Hi all! I have a basic doubt but I'm stuck with it... How can I continue and accept an empty input? using this: val scanner = Scanner(System.in) val myNum = scanner.nextInt() I must always insert a number for programm to continue. But I wanted to insert nothing and just press enter for the programm to continue. And this way, myNum val would be empty been googling it, but I think I'm not knowing how to search for it correctly..
m
Hi, you probably want nullable integer -
Int?
. By using
nextLine
, feeding newline will cause the scanner to stop reading
Copy code
val scanner = Scanner(System.`in`)
    val myNum = scanner.nextLine().toIntOrNull()
🙌 1
m
yes, I can work with this! 😄 thank you!
👋 1
just tested it