Hi,
I know matrix 2d can be written like array[5][5] which saying 5x5 matrix but how do i make the row is like sequence of alphabets so its like array[a...z][5] while the column still numbers. Thanks.
Hi,
I know matrix 2d can be written like array[5][5] which saying 5x5 matrix but how do i make the row is like sequence of alphabets so its like array[a...z][5] while the column still numbers. Thanks.
Jump to PostDo you mean to declare an array[26][5] so you can access individual elements with syntax like array[2]?
Jump to PostIn Java chars are numbers according to the ASCII/Unicode tables, eg 'a' is 97, so you can use chars to index into an array:
a[2] is valid and identical to a[97][2]
You can also use them in arthmetic, so, for example
char x = 'a';
a[x-'a'][2] is valid and identical …
Do you mean to declare an array[26][5] so you can access individual elements with syntax like array[2]?
yep. its like row and column but the row is number while the column is alphabets in order. from the array its only like declaring numbers and not characters
its like making an excel row and column where it has like [A][1] = 1; [1] = 2. something like that. is there any method i can use?thanks.
In Java chars are numbers according to the ASCII/Unicode tables, eg 'a' is 97, so you can use chars to index into an array:
a[2] is valid and identical to a[97][2]
You can also use them in arthmetic, so, for example
char x = 'a';
a[x-'a'][2] is valid and identical to a[0][2]
char x = 'b';
a[x-'a'][2] is valid and identical to a[1][2]
etc.
(that was a hint!)
Hi,
Thanks for the hint. after i created the matrix, i need to do a uniform cost search on the array so it can find the best path from start to the end point. any idea or tips how i can start on implement the algorithm? thanks
Sorry, I think you need a mathematician, not a humble coder for that.
or maybe use A* star search algorithm. Thanks.
We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.