0

I have a 10x10 int[][], each element is a random int. For my specific purpose, I need to convert each int value into a String so I can use those values as an argument in Label(text: String). I want to be able to traverse my array and do this conversion on each iteration. Obviously this is all I can muster up for this problem:

for (int row = 0; row < matrix.length; row++) {
            for (int column = 0; column < matrix[row].length; column++) {


            }
        }

I tried using the toString() on each index, but NetBeans wasn't liking it, because I was obviously using it incorrectly. So if someone could give me some guidance on how this process works it would be greatly appreciated. And it may go without saying, but I'm still learning.

0

1 Answer 1

1

Your loops seems to be alright. User Integer.toString() to convert an int to a String

for (int row = 0; row < matrix.length; row++) 
{
    for (int column = 0; column < matrix[row].length; column++) 
    {
       String matrixElementStr = Integer.toString(matrix[row][column]); 

       // Call some method "Label(text: String)" with  "matrixElementStr" as a parameter
    }
}
Sign up to request clarification or add additional context in comments.

4 Comments

So for every iteration is each index being tacked onto elementStr as one long String? Or is each index just becoming a String that elementStr can reference to?
each element (unique combination [row][column])in the matrix is converted to a string. which is what the OP asks for
I see. Then in the second iteration, this means matrixElementStr is referring to the current index which at the same time is converted to a String, yeah? Sorry for the drawn out questions, I just want to make sure I got a grip on what exactly is happening so I can understand.
best way to undertand this code is the outer loop runs once for each row. For each row the inner loop runs x times. where x is number of columns.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.