Question

I am wondering how I can take in input from the console in a specific format.

I'm looking to ask the user for an input in the format of

  • #,# or
  • ##

and translate that into

  • #,# or
  • split the two numbers in some fashion

So that I can use those two numbers to find an object in a 2D array.

Essentially what I'm trying to do...

Ask user for input
Scanner take in values in form #,# or ##
Then be able to use/plug in values into 2D array 
So array[#][#] in some sort

Any help would be greatly appreciated, thank you in advance !

Was it helpful?

Solution

You can't take the data already formatted, but you can input the data as a String and format at.

Take a look at NumberFormat for formatting the number.

If you want to get each digit from a string, try getting the char from the String for each number, and then convert it to an Integer or an int.

OTHER TIPS

I would use a regex for the input and then change it into ints

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top