I want to understand how char
stores in 2xn char matrix
For example
int numWords = in.nextInt();
char[][] words = new char[numWords][];
In above code, words
is char
matrx which can store numWords
number of rows and n
number of columns in every row. Correct ?
for (int i = 0; i < numWords; i++) {
words[i] = in.next().toCharArray();
System.out.println("in.next().toCharArray():"+words[i][i]);
}
If I run above code with numWords
is equals to 1
and having value a 1
Then how the char
array returned by in.next().toCharArray()
will save into words
char matrix ?
How matrix will look like ?
Update:
With numWords
equals to 1
If an char array
is having value a, ,1
and print like this
System.out.println("Values:"+words[i][i] + "------"+words[i][i+1]);
Why its showing below error ? In first row there should be 3 columns ?
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException : 1