0

Java Array char num access

how can I declare an array like array[A,2], gettin number with row and column alfanumeric?

6th Nov 2019, 3:59 AM
Kevin Fernandez Esquivel
Kevin Fernandez Esquivel - avatar
7 odpowiedzi
+ 5
Creat object type array Example Object[] arr = {"A",2};
6th Nov 2019, 5:18 AM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 4
Object[] arr ={ {"A",1,2,3,4,5} {"B",6,7,8,9,10} };
7th Nov 2019, 8:23 AM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 1
Hello Kevin, Can you describe in more detailed way, what are you trying to do with this array? I don't seem to understand where you're going with the idea : )
7th Nov 2019, 7:11 AM
Ipang
+ 1
for example, I have a table, where the columns name are letters and the rows are number, if I want to get a specific cell, I have to write int number =array["A",5], in this case my array has 8 rows and 8 columns filled it with random numbers
8th Nov 2019, 1:09 AM
Kevin Fernandez Esquivel
Kevin Fernandez Esquivel - avatar
+ 1
+- A B C D E F G H 1 10 20 30 40 50 60 70 80 2 20 30 40 50 60 70 80 90 3 ... 4 ... 6 ... 7 ... 8 ... Kevin you mean like this? public class Learning { public static void main(String[] args) { int d = 8; int [][] arr = new int[d][d]; for(int r = 0, n = 10; r < d; r++) { for(int c = 0; c < d; c++, n += 10) { arr[r][c] = n; } } System.out.println(arr[5][charToIndex('F', d)]); } private static int charToIndex(char c, int maxValid) { if(!Character.isLetter(c)) return 0; int index = ((int)Character.toUpperCase(c)) - 65; if(index < 0 || index >= maxValid) return 0; return index; } }
8th Nov 2019, 5:44 AM
Ipang
+ 1
yes something like this, I am going to analize, thanks
9th Nov 2019, 4:29 AM
Kevin Fernandez Esquivel
Kevin Fernandez Esquivel - avatar
0
what happen if array is like a table with n rows and n columns?
7th Nov 2019, 12:40 AM
Kevin Fernandez Esquivel
Kevin Fernandez Esquivel - avatar