Aadi Aadi - 1 month ago 8
Java Question

How to take input in java without spaces?

How can i take input for an integer array in a single line without spaces. Number can be only from 0-9 so every thing is single digit.

Input:-

123456


Output:-

a[0]=1 a[1]=2 a[2]=3 a[3]=4 a[4]=5 a[5]=6


Please help me with this issue.

Answer

Take in in as a String and use split() -method like this:

"123".split("(?!^)")

will produce an array of strings

array ["1", "2", "3"]

Comments