Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing variables

 
andy hough
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have produced a program which in short is shown below:

public class Main{
public Main(){
}

public static void main(String[] args){
int array[][]=new int[65][65];
enter some values into the array;

functionOne(1);

output the array showing the changes made by functionOne()
}

public void functionOne(int x){
change the value of array[x][2];
}
}

However, I get various errors about either the array isnot accessible or I cannot reference from a static to a non static.

How would I achieve the above code?

Many thanks in advance
 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change



to

 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or create a Main object and call the method with that
 
andy hough
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok I did that, but within the functionOne() i get errors saying symbol cant be found, syymbol=array
 
fred rosenberger
lowercase baba
Bartender
Posts: 12185
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy,

It's kind of tough to diagnose the problem with a) the real code, and b) the exact text of the error message.

we could guess, but if you'd post both, that would help.

PLEASE use the 'code' tags to preserve your formatting. press that little 'code' button in the "instant UBB Code" section, then past your code between the tags it generates.

thanks!!!
 
andy hough
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, here is the which was represented by functionOne():



the error messages are all variations of:
 
fred rosenberger
lowercase baba
Bartender
Posts: 12185
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where is dlxGrid defined? What the message is telling you is that this variable is out of scope. if it's declared in a method, then it goes out of scope when that method closes.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic