Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 15th, 2007, 1:28 AM   #1
paulchwd
Hobbyist Programmer
 
paulchwd's Avatar
 
Join Date: Mar 2005
Posts: 139
Rep Power: 4 paulchwd is on a distinguished road
Exclamation Matrices

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
paulchwd is offline   Reply With Quote
Old Apr 15th, 2007, 1:54 AM   #2
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 841
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
If you know how to get user input, then creating a 2D array is simple enough:

int[][] matrix = new int[numRows][numCols];
You can access a specific element of the array as matrix[row][col].

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.
titaniumdecoy is offline   Reply With Quote
Old Apr 15th, 2007, 12:40 PM   #3
paulchwd
Hobbyist Programmer
 
paulchwd's Avatar
 
Join Date: Mar 2005
Posts: 139
Rep Power: 4 paulchwd is on a distinguished road
Exclamation

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
paulchwd is offline   Reply With Quote
Old Apr 15th, 2007, 3:04 PM   #4
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 841
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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.
titaniumdecoy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:36 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC