![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 139
Rep Power: 4
![]() |
Hi,
i want to get the size of a matrix from a user at the command line and then prompt them to enter the values to be stored in the matrix, i cant wrap my head around 2d arrays (programming them, can you help me pls. thnx x10 |
|
|
|
|
|
#2 |
|
Expert Programmer
|
If you know how to get user input, then creating a 2D array is simple enough:
int[][] matrix = new int[numRows][numCols]; If you need more help, your best bet would be to search the web for answers. A Google search for "2d array java" turns up a multitude of resources. |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 139
Rep Power: 4
![]() |
im am using stringtokenizer to tokenize the user input (first row of data), but where do i put the while(st.hasMoreTokens()) loop?, here is my code:
StringTokenizer st = new StringTokenizer(data);
for (int i=0; i<=row-1; i++ )
{
System.out.println("I= " + i);
for(int j=0; j<=col-1; i++)
{
System.out.println("J= " + j);
addArray1[i][j]=Integer.parseInt(st.nextToken());
}
}thnx x 10 |
|
|
|
|
|
#4 |
|
Expert Programmer
|
Will you please stop rating all your threads 5 stars? The exclamation mark sign isn't necessary either. Your posts will be read.
If you expect the user to enter a specific number of tokens, a for loop would likely be preferable to a while loop. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 2-dimensional matrices | PhilBon | Software Design and Algorithms | 1 | Mar 10th, 2007 11:18 AM |
| Multiplying Matricies help | Thanatos5142 | Java | 8 | Oct 23rd, 2006 7:26 PM |
| geometric series with Matrices | brad sue | C | 3 | Mar 6th, 2006 2:14 AM |
| Matrices and Defining my Array Question | TecBrain | C++ | 2 | Mar 2nd, 2005 4:46 PM |
| Matrices Tutorial. | TecBrain | C++ | 1 | Feb 26th, 2005 4:03 PM |