Click here to Skip to main content
15,908,013 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
package javanew;
Java
public class JavaNew
{
    public static void main(String args[])
    {
       int twoD[][]=new int[4][5];
       int i,j,k=0;
       for(i=0;i<4;i++)
       {
           for(j=0;j<5;j++)
           {
               twoD[i][j]=k;
               k++;
           }
       }
       for(i=0;i<4;i++)
       {
           for(j=0;j<5;j++)
           {
               System.out.print(twoD[i][j]+" ");    
           }
           System.out.println();
       }
    }
}


Output:
0 1 2 3 4 
5 6 7 8 9 
10 11 12 13 14 
15 16 17 18 19
Posted
Updated 3-Jan-16 2:29am
v3
Comments
ridoy 3-Jan-16 8:31am    
Find 2 dimensional array tutorial somewhere and learn it from there. Then debug this code, that's all.

No.
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!

Besides, do you have any idea how much work explaining code line by line is?
Every single line needs a paragraph of explanation! For example:
int next = r.Next();

Create a new variable called "next" which can hold a integer value. From the previously declared Random instance "r", call the "Next" method to get a new random number, and assign it to the "next" variable.

Can you imagine how long it would take us to explain even a very short code fragment like your example, line by line?

No. It is not going to happen. If you have a specific problem, then ask a question about it. But think first - would you want to sit down for 45 minutes and type up a line-by-line description for no good reason?
 
Share this answer
 
You can easily find answers to questions like this by reading the documentation[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900