0

I am a 1st year student, and I don't know what to do here. I have input values but I keep getting 0 as a result. I am expecting output like this:

0000000000

1111111111

2222222222

3333333333

4444444444

but it keeps on giving me 0.

Here is my code so far:

    String [][]array2D = new String[5][10];

    for(int r=0; r<array2D.length; r++)
    {
        for(int b=0; b<array2D[r].length; b++)
        {
            System.out.print(array2D[r][b]);    
        }
        System.out.println();
    }

    System.out.println("Prepared By: Mark Vincent D. Yap");
}

2 Answers 2

1

This gives the desired result:

    String [][]array2D = new String[5][10];

    for(int r=0; r<array2D.length; r++)
    {
        for(int b=0; b<array2D[r].length; b++)
        {
            array2D[r][b] = Integer.toString(r);
        }
        System.out.println();
    }

    for(int r=0; r<array2D.length; r++)
    {
        for(int b=0; b<array2D[r].length; b++)
        {
            System.out.print(array2D[r][b]);
        }
        System.out.println();
    }

    System.out.println("Prepared By: Diligent Key Presser");

Hope you will take advance of this, not just copy and paste.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you so much sir @Diligent Key Presser ^^ i have to cram for finals ^^ so i am in kinda rush
0

you just forgot to put inputs (filling array values) in your., rest of fine. See below is your code in which I just added array value input statement.

String [][]array2D = new String[5][10];

for(int r=0; r<array2D.length; r++)
{
    for(int b=0; b<array2D[r].length; b++)
    {
        array2d[r][b]=String.values(r);  
        System.out.print(array2D[r][b]);    
    }
    System.out.println();
}

System.out.println("Prepared By: Mark Vincent D. Yap");

}

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.