• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

passing variables

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change



to

 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok I did that, but within the functionOne() i get errors saying symbol cant be found, syymbol=array
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic