Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Mar 11th, 2005, 4:27 PM   #1
Tazz_Mission_13
Newbie
 
Join Date: Mar 2005
Posts: 2
Rep Power: 0 Tazz_Mission_13 is on a distinguished road
Converting 1-dimensional array to 2-dimensional array

Hello,

I was wondering if someone can help me figure out the issue that I cannot seem to get around. I have been attempting to convert a 1-Dimensional array to a 2-Dimensional array (also called a matrix), but just cannot figure out how to do it. Here are the parameters:

--- I have a 1-Dimensional array of characters that has length 36,
called array1. The array is:
abcdefghijklmnopqrstuvwxyz0123456789

--- The 2-Dimensional array, called matrix, is 6x6, so it is square and can
hold all the 36 characters from array1.

What I want to do is convert the array1 to matrix starting with the upper right corner. An example of this would be:
              a  ---->    ba  ---->    dba   --->    gdba
                           c            ec            hec
                                         f             if
and so on untill all 36 characters are inserted into the matrix.

If anyone can help me I would really appreciate it.

Thankz,

Tazz

Last edited by Tazz_Mission_13; Mar 11th, 2005 at 4:30 PM.
Tazz_Mission_13 is offline   Reply With Quote
Old Mar 12th, 2005, 11:41 PM   #2
Tazz_Mission_13
Newbie
 
Join Date: Mar 2005
Posts: 2
Rep Power: 0 Tazz_Mission_13 is on a distinguished road
[solved]

I got the solution my self
Tazz_Mission_13 is offline   Reply With Quote
Old Mar 13th, 2005, 12:18 AM   #3
Xero
Hobbyist Programmer
 
Join Date: Dec 2004
Location: a cardboard box
Posts: 118
Rep Power: 4 Xero is on a distinguished road
Glad you found it...

Shouldn't have been that bad
__________________
...
Xero is offline   Reply With Quote
Old Apr 4th, 2005, 8:27 AM   #4
nanoh2001
Newbie
 
Join Date: Apr 2005
Posts: 5
Rep Power: 0 nanoh2001 is on a distinguished road
hi,,,

can u write the sulution pleaze??
nanoh2001 is offline   Reply With Quote
Old Apr 4th, 2005, 3:23 PM   #5
Childe Roland
Newbie
 
Childe Roland's Avatar
 
Join Date: Mar 2005
Posts: 17
Rep Power: 0 Childe Roland is on a distinguished road
i think i would of attempted it using nested for loops but I would like to see how someone else would do it if anybody would like to post the code for it
Childe Roland is offline   Reply With Quote
Old Apr 5th, 2005, 2:37 PM   #6
nanoh2001
Newbie
 
Join Date: Apr 2005
Posts: 5
Rep Power: 0 nanoh2001 is on a distinguished road
pllllz put the code i need it nessesary ... for the assigment plazzz
nanoh2001 is offline   Reply With Quote
Old Apr 8th, 2005, 11:58 AM   #7
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 370
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
I know, i'm slow .. but i haven't got the time to think about it. Here it is:
import java.io.*;

class matrix {
	public static void main(String args[]){
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		
                int n=3;


		int a[][]=new int[3][3];
		int i=0;  //row
		int j=0;  //colomn
		int step=1; // used when under the main diagonal
		int pas=0;  // used when above the main diagonal
		

		for(;;){
			if(pas<=n-1){
				i=0;
				j=n-1-pas;

				do{
					try{
						String s=in.readLine();
						int x=Integer.parseInt(s);
                               //see if the index is working
						System.out.println("i="+i+" "+"j="+j);

						a[i][j]=x;
						i++;
						j++;
						}
					catch(IOException e){e.printStackTrace();}
				}while(i<=pas);
				pas++;
			}

			if(pas>n-1){
				i=step;
				j=0;

				do{
					try{
						String s=in.readLine();
						int x=Integer.parseInt(s);
                               //see if the index is working
					System.out.println("i="+i+" "+"j="+j);
					a[i][j]=x;
					i++;
					j++;

					}catch(IOException e){e.printStackTrace();}
				}while(i<=n-1);
				step++;
			}
		if((step>n-1))break;
		}
//see if it worked :)
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			System.out.print(a[i][j]);}
	System.out.println();}
}
}
__________________
Don't take life too seriously, it's not permanent !
xavier 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




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

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