Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old May 27th, 2006, 8:11 AM   #1
tumbleTetris
Programmer
 
Join Date: May 2006
Posts: 39
Rep Power: 0 tumbleTetris is on a distinguished road
passing variables from one method to another?

public class something
{
	public void methodOne()
	{
		int i = 0;
		int x = 4;
		String word = "hello";
		
		int[] abc = new int[26];
        while( i < 26) 
        {
            abc[i] = x;
            x++;
            i++;
        }
        
        methodTwo(i, x, word, abc);
	}


	public void methodTwo(i, x, word, abc)
	{
		int a = i;
		int b = x;
		String c = word;
		int d = abc;
	}


}
I tried that, but it didn't work, I got an <identifier>expected and ')' expected error...
tumbleTetris is offline   Reply With Quote
Old May 27th, 2006, 8:33 AM   #2
Toro
Hobbyist Programmer
 
Toro's Avatar
 
Join Date: Apr 2006
Posts: 136
Rep Power: 0 Toro is an unknown quantity at this point
methodTwo doesn't have any variable types declared.
[PHP]
//this works
public class something
{
public void methodOne()
{
int i = 0;
int x = 4;
String word = "hello";

int[] abc = new int[26];
while( i < 26)
{
abc[i] = x;
x++;
i++;
}

methodTwo(i, x, word, abc);
}
public void methodTwo( int i, int x, String word, int abc[])
{
int a = i;
int b = x;
String c = word;
int d[] = abc;
}
}
[/PHP]
btw, please work at the issue before posting, these are common program errors and it shows us that you do not know what you are doing. I advise you to read up so references.
Toro is offline   Reply With Quote
Old May 27th, 2006, 8:42 AM   #3
tumbleTetris
Programmer
 
Join Date: May 2006
Posts: 39
Rep Power: 0 tumbleTetris is on a distinguished road
yeah, thanks, I noticed.

I have been a little jumpy recently...
tumbleTetris is offline   Reply With Quote
Old May 28th, 2006, 8:24 AM   #4
tumbleTetris
Programmer
 
Join Date: May 2006
Posts: 39
Rep Power: 0 tumbleTetris is on a distinguished road
well I just have hit another stumbling block, I can't invoke a method that has a passed array within its argument.

like if I have:
    public void initAbc(){
        String[] abc = new String[7];
        //destinations within array
        abc[0] = "[1]   fasd";
        abc[1] = "[2]   fdas";
        abc[2] = "[3]   dfafsd";
        abc[3] = "[4]   Hedfrmes";
        abc[4] = "[5]   dfas";
        abc[5] = "[6]   dfas";
        abc[6] = "[7]   asdfasfds";
        
        printDestinations( abc );
    }
    
    public void printAbc( String abc[] )
    {
        int i = 0;
        while ( i < 7 )
        {
            System.out.println(abc[i]);
            i++;
        }
    }

if I try to invoke it in another class, for instance:

classSomething abc = new classSomething();

abc.initAbc();

abc.printAbc(); <-- doesn't work.
tumbleTetris is offline   Reply With Quote
Old May 28th, 2006, 10:22 AM   #5
Toro
Hobbyist Programmer
 
Toro's Avatar
 
Join Date: Apr 2006
Posts: 136
Rep Power: 0 Toro is an unknown quantity at this point
First of all, it doesn't work because printAbc() contains arguments and to me it looks like it doesnt have any arguments! And doesn't initAbc() call printtAbc automatically?
Toro 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 5:20 AM.

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