I am just wondering if anyone could show me some code as to how I would put this string in a 2D boolean array and print it out
Example: “0-1 0-2 1-2 1-3 2-3” , however the string could be more complicated like this “0-1 1-2 2-3 3-0 0-4 0-11 1-5 1-6 2-7 2-8 3-9 3-10 4-5 6-7 8-9 10-11 4-7 4-8 5-9 5-10 6-9 6-10 7-11 8-11”
An example would be 0-1 is true, 0-2 is true, 1-2 is true, 1-3 is true, 2-3 is true, all other postions should be false
I don’t know what you mean by putting them in a 2D
booleanarray. If you have problem with parsing the text, then here are some snippet of code you can use.For the first solution, I assume that the numbers always come in pairs and are separated by a single
-, and space is used to delimit between the pairs of numbers.Use this if you are reading from standard input:
Use this if you have a
Stringcontains all the numbers and you want to process it (let the name of the variable beinputString):Then you can read the numbers from the input:
Alternatively, you can also use useDelimiter to add
-as delimiter and usenextIntto read number without having to deal with-separately:The code will simply becomes:
The code is cleaner, but whether
-appear betweenfirstandsecond, or how many-appear, or is it the only character between the pair of numbers not is not known now. It is OK if we assume the input format is correct. However, if that assumption is not given, we can’t do any input validation.