0

I want to fill my array with random numbers, but I can't show in the TextViewer my array casual[] - help me!

LanciaB.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {

        int result = np2.getValue();
        int result2 = np.getValue();
        result = result == 0 ? 10 : result;

        int casual[] = new int[10];
        for(int i=0; i < result2; i++){
            casual[i] = (int) (Math.random()*10);
        }

        tv.setText(casual.toString());

        }
    });

3 Answers 3

4

Use overloaded Arrays#toString(int[]) of Arrays which takes array as an argument.

 Arrays.toString(casual)
Sign up to request clarification or add additional context in comments.

1 Comment

Thx! I used your advice but the string that is printed is not only numbers but also characters and letters ... is a printing problem or is the wrong way fill the array of random numbers?
1

You need to join the elements of the array. In Android you can do something like this:

tv.setText(TextUtils.join(",", casual));

Comments

0

I used your advice but the string that is printed is not only numbers but also characters and letters ... is a printing problem (string encoding) or is the wrong way fill the array of random numbers?

Comments

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.