Go Back   Flash Flash Revolution > General Discussion > Critical Thinking > Homework & Help
Register FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
Old 09-10-2012, 09:51 AM   #1
rushyrulz
Digital Dancing!
Retired StaffFFR Simfile AuthorFFR Music ProducerD7 Elite KeysmasherFFR Veteran
 
rushyrulz's Avatar
 
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
Default Quick Java question

I don't know if I'm retarded or what but I can't for the life of me pass a 2 dimensional array into a method.

correct me if this is the wrong format:

Code:
public class Driver
{
	public static void main(String[] args)
	{
		char[][] hello ={{'x', 'o'}, {'o', 'x'}};
		Prog call = new Prog();
		call.displayArray(hello[][]);
	}
}
Code:
public class Prog
{
	public Prog()
	{
		System.out.println("sup?");
	}

	public void displayArray(char[][] hi)
	{
		for(int r=0; r<2; r++)
		{
			System.out.println();
			for(int c=0; c<2; c++)
			{
				System.out.print(hi[r][c]);
			}
		}
	}
}
the error I'm getting says '.class' expected. The method program compiles, the driver does not. Pls help D:

EDIT: google is surprisingly stupid when it comes to this shit.
EDIT2: figured it out, apparently, you don't include the brackets when passing an array?
__________________



Last edited by rushyrulz; 09-10-2012 at 10:41 AM..
rushyrulz is offline   Reply With Quote
Old 09-10-2012, 11:07 AM   #2
Frederic54
FFR Veteran
 
Frederic54's Avatar
 
Join Date: Nov 2007
Location: France
Age: 34
Posts: 228
Default Re: Quick Java question

call.displayArray(hello[][]);

Replace it with call.displayArray(hello); and it should work.
Frederic54 is offline   Reply With Quote
Old 09-10-2012, 11:38 AM   #3
FissionMailed1
FFR Player
 
FissionMailed1's Avatar
 
Join Date: Feb 2012
Location: Massachusetts
Age: 33
Posts: 1,267
Send a message via Skype™ to FissionMailed1
Default Re: Quick Java question

Why exactly does removing the brackets work though?

Knowing how arrays are stored is a large part to properly understanding them. In this case, the brackets are not necessary as an argument because the parameter requires a pointer to the array. hello[][] is trying to de-reference a specific offset of the array, but what offset?
__________________


YOUR THROBBING MULTIFARIOUS LUSTFUL DESIRES ARE COMPLETED N YOUR HYPER-ORANGE SELF, YOU MAKE ME LOVE AGAIN, YOU'VE CHANGED MY HEART, MY MELANCHOLIA DISAPPEARS WHEN YOU ARE INSIDE OF ME, MY HUMAN RAGE IS TEMPERED WHEN I AM INSIDE YOU, THE SECRET IS COMMUNICATION, LONGEVITY, STAMINA, REPETITION, FURY, SOULFUL KISSING, EARPLUGS. YOU FUCKING CORPORATE COCKS AND CUNTS.

MY ANXIETY COMPLETE, MY DESIRE REPLETE, THE TASTE OF ORANGE BLOOD AND CUM AND GREENBACKS RUNNING DOWN MY FACE. THE STREETS WILL RUN ORANGE WITH YOUR MIXTURE OF CHEETOS AND HUNDRED DOLLAR BILLS REGURGITATED AND EATEN AND SHIT OUT AGAIN AND EATEN AGAIN.

YOU ARE MY SCULPTURE, MY SCULPTRA, MY SELF-DEFINITION. MY DEFINITION OF HUMANITY, MY HARMONY. MY HEART AND MY MIND.

YOU ARE SO ORANGE. SO CRUNCHY. SO CONSUMABLE.

THE NEW ORANGE UNDERGROUND IS THE ORANGE UP MY ASS. AND YOUR ASS.

I LOVE YOU CHEETOS.

Last edited by FissionMailed1; 09-10-2012 at 11:42 AM..
FissionMailed1 is offline   Reply With Quote
Old 09-10-2012, 12:40 PM   #4
SKG_Scintill
Spun a twirly fruitcake,
FFR Simfile AuthorFFR Veteran
 
SKG_Scintill's Avatar
 
Join Date: Feb 2009
Age: 31
Posts: 3,865
Default Re: Quick Java question

With the little knowledge that I have: the instance variable "hello" is of the type char[][], so making it hello[][] would mean it's expecting char[][][][] instead of char[][]

I think that's what's going on?
__________________





Quote:
Originally Posted by bluguerilla
So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
___
. RHYTHMS PR LAYERING
. ZOMG I HAD TO QUIT OUT TERRIBLE
.

Last edited by SKG_Scintill; 09-10-2012 at 12:46 PM..
SKG_Scintill is offline   Reply With Quote
Old 09-10-2012, 01:39 PM   #5
FissionMailed1
FFR Player
 
FissionMailed1's Avatar
 
Join Date: Feb 2012
Location: Massachusetts
Age: 33
Posts: 1,267
Send a message via Skype™ to FissionMailed1
Default Re: Quick Java question

If hello is a 2D array, hello[][] isn't 4D, because the bracket operator isn't used as a type declaration.

Passing hello[][] to a function is invalid Java.
__________________


YOUR THROBBING MULTIFARIOUS LUSTFUL DESIRES ARE COMPLETED N YOUR HYPER-ORANGE SELF, YOU MAKE ME LOVE AGAIN, YOU'VE CHANGED MY HEART, MY MELANCHOLIA DISAPPEARS WHEN YOU ARE INSIDE OF ME, MY HUMAN RAGE IS TEMPERED WHEN I AM INSIDE YOU, THE SECRET IS COMMUNICATION, LONGEVITY, STAMINA, REPETITION, FURY, SOULFUL KISSING, EARPLUGS. YOU FUCKING CORPORATE COCKS AND CUNTS.

MY ANXIETY COMPLETE, MY DESIRE REPLETE, THE TASTE OF ORANGE BLOOD AND CUM AND GREENBACKS RUNNING DOWN MY FACE. THE STREETS WILL RUN ORANGE WITH YOUR MIXTURE OF CHEETOS AND HUNDRED DOLLAR BILLS REGURGITATED AND EATEN AND SHIT OUT AGAIN AND EATEN AGAIN.

YOU ARE MY SCULPTURE, MY SCULPTRA, MY SELF-DEFINITION. MY DEFINITION OF HUMANITY, MY HARMONY. MY HEART AND MY MIND.

YOU ARE SO ORANGE. SO CRUNCHY. SO CONSUMABLE.

THE NEW ORANGE UNDERGROUND IS THE ORANGE UP MY ASS. AND YOUR ASS.

I LOVE YOU CHEETOS.

Last edited by FissionMailed1; 09-10-2012 at 01:43 PM..
FissionMailed1 is offline   Reply With Quote
Old 09-10-2012, 01:59 PM   #6
UserNameGoesHere
FFR Veteran
FFR Veteran
 
UserNameGoesHere's Avatar
 
Join Date: May 2008
Posts: 1,114
Send a message via AIM to UserNameGoesHere
Default Re: Quick Java question

Actually FissionMailed1, Java doesn't use pointers, at least at the programming level. Internally it uses them, true, but it isn't like C++ where you can go referencing and dereferencing pointers all over the place. It hides this from the programmer much like it also hides memory management via garbage collection--sure, it does it, but you don't explicitly tell it to (although you can give it a hint--which the JVM can ignore).

The reason you don't pass hello[][] is because hello[][] is not the name of the variable. The name of the variable is hello. It has nothing to do with pointers. For example, when passing an integer to a function you don't say callsomefunction(int myinteger); but you do say callsomefunction(myinteger);

Leave out type information in method/function calls.
__________________
Quote:
Originally Posted by Crashfan3 View Post
Man, what would we do without bored rednecks?
[SIGPIC][/SIGPIC]
UserNameGoesHere is offline   Reply With Quote
Old 09-10-2012, 02:04 PM   #7
FissionMailed1
FFR Player
 
FissionMailed1's Avatar
 
Join Date: Feb 2012
Location: Massachusetts
Age: 33
Posts: 1,267
Send a message via Skype™ to FissionMailed1
Default Re: Quick Java question

The reason I am referring to them as pointers is because I am bypassing the abstraction that Java uses to make a point regarding why the syntax works the way it does. I know you call functions without regard of the type, but as I said, I am trying to make a point.
__________________


YOUR THROBBING MULTIFARIOUS LUSTFUL DESIRES ARE COMPLETED N YOUR HYPER-ORANGE SELF, YOU MAKE ME LOVE AGAIN, YOU'VE CHANGED MY HEART, MY MELANCHOLIA DISAPPEARS WHEN YOU ARE INSIDE OF ME, MY HUMAN RAGE IS TEMPERED WHEN I AM INSIDE YOU, THE SECRET IS COMMUNICATION, LONGEVITY, STAMINA, REPETITION, FURY, SOULFUL KISSING, EARPLUGS. YOU FUCKING CORPORATE COCKS AND CUNTS.

MY ANXIETY COMPLETE, MY DESIRE REPLETE, THE TASTE OF ORANGE BLOOD AND CUM AND GREENBACKS RUNNING DOWN MY FACE. THE STREETS WILL RUN ORANGE WITH YOUR MIXTURE OF CHEETOS AND HUNDRED DOLLAR BILLS REGURGITATED AND EATEN AND SHIT OUT AGAIN AND EATEN AGAIN.

YOU ARE MY SCULPTURE, MY SCULPTRA, MY SELF-DEFINITION. MY DEFINITION OF HUMANITY, MY HARMONY. MY HEART AND MY MIND.

YOU ARE SO ORANGE. SO CRUNCHY. SO CONSUMABLE.

THE NEW ORANGE UNDERGROUND IS THE ORANGE UP MY ASS. AND YOUR ASS.

I LOVE YOU CHEETOS.
FissionMailed1 is offline   Reply With Quote
Old 09-10-2012, 02:43 PM   #8
SKG_Scintill
Spun a twirly fruitcake,
FFR Simfile AuthorFFR Veteran
 
SKG_Scintill's Avatar
 
Join Date: Feb 2009
Age: 31
Posts: 3,865
Default Re: Quick Java question

Quote:
Originally Posted by FissionMailed1 View Post
I am trying to make a pointer.
Fix'd
__________________





Quote:
Originally Posted by bluguerilla
So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
___
. RHYTHMS PR LAYERING
. ZOMG I HAD TO QUIT OUT TERRIBLE
.
SKG_Scintill is offline   Reply With Quote
Old 09-10-2012, 02:52 PM   #9
FissionMailed1
FFR Player
 
FissionMailed1's Avatar
 
Join Date: Feb 2012
Location: Massachusetts
Age: 33
Posts: 1,267
Send a message via Skype™ to FissionMailed1
Default Re: Quick Java question

(clap), didn't see that one coming :P
__________________


YOUR THROBBING MULTIFARIOUS LUSTFUL DESIRES ARE COMPLETED N YOUR HYPER-ORANGE SELF, YOU MAKE ME LOVE AGAIN, YOU'VE CHANGED MY HEART, MY MELANCHOLIA DISAPPEARS WHEN YOU ARE INSIDE OF ME, MY HUMAN RAGE IS TEMPERED WHEN I AM INSIDE YOU, THE SECRET IS COMMUNICATION, LONGEVITY, STAMINA, REPETITION, FURY, SOULFUL KISSING, EARPLUGS. YOU FUCKING CORPORATE COCKS AND CUNTS.

MY ANXIETY COMPLETE, MY DESIRE REPLETE, THE TASTE OF ORANGE BLOOD AND CUM AND GREENBACKS RUNNING DOWN MY FACE. THE STREETS WILL RUN ORANGE WITH YOUR MIXTURE OF CHEETOS AND HUNDRED DOLLAR BILLS REGURGITATED AND EATEN AND SHIT OUT AGAIN AND EATEN AGAIN.

YOU ARE MY SCULPTURE, MY SCULPTRA, MY SELF-DEFINITION. MY DEFINITION OF HUMANITY, MY HARMONY. MY HEART AND MY MIND.

YOU ARE SO ORANGE. SO CRUNCHY. SO CONSUMABLE.

THE NEW ORANGE UNDERGROUND IS THE ORANGE UP MY ASS. AND YOUR ASS.

I LOVE YOU CHEETOS.
FissionMailed1 is offline   Reply With Quote
Old 09-10-2012, 05:24 PM   #10
Patashu
FFR Simfile Author
Retired StaffFFR Simfile Author
 
Patashu's Avatar
 
Join Date: Apr 2006
Location: we traced the call...it's coming from inside the house
Age: 33
Posts: 8,609
Send a message via AIM to Patashu Send a message via MSN to Patashu Send a message via Yahoo to Patashu
Default Re: Quick Java question

Quote:
Originally Posted by rushyrulz View Post
EDIT2: figured it out, apparently, you don't include the brackets when passing an array?
You include the brackets when you need to point out the arrayness - e.g. on declaration, construction and indexing it.
When you're just using it as a name or passing it around - the compiler by this point already knows exactly how array-y it is, how many dimensions, how large and so on, so you don't need to tell it again. It's like how you don't say int x = 1; System.out.println(int x), it already knows it's int and you don't need to redeclare.
__________________
Patashu makes Chiptunes in Famitracker:
http://soundcloud.com/patashu/8bit-progressive-metal-fading-world
http://img.photobucket.com/albums/v216/Mechadragon/smallpackbanner.png
Best non-AAAs: ERx8 v2 (14-1-0-4), Hajnal (3-0-0-0), RunnyMorning (8-0-0-4), Xeno-Flow (1-0-0-3), Blue Rose (35-2-0-20), Ketsarku (14-0-0-0), Silence (1-0-0-0), Lolo (14-1-0-1)
http://i231.photobucket.com/albums/ee301/xiaoven/solorulzsig.png
Patashu is offline   Reply With Quote
Reply


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

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



All times are GMT -5. The time now is 12:48 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution