0
Java Array char num access
how can I declare an array like array[A,2], gettin number with row and column alfanumeric?
7 Respuestas
+ 5
Creat object type array
Example
Object[] arr = {"A",2};
+ 4
Object[] arr ={
{"A",1,2,3,4,5}
{"B",6,7,8,9,10}
};
+ 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 : )
+ 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
+ 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;
}
}
+ 1
yes something like this, I am going to analize, thanks
0
what happen if array is like a table with n rows and n columns?