Computer Science Canada

need help with returning variables

Author:  shadowman571 [ Sat Oct 06, 2007 4:24 pm ]
Post subject:  need help with returning variables

I need help returning a variable from one method to the main method of my program, plain and simple I cant find how to do it.

Can anyone explain how i would go about doing this?

what i mean by this is
if i were to make

public static void main(string[] args)
{
}
public static void vars(string[]args)
{
string name ="Alan"
}

how would i send the information held in name back to main?

Author:  wtd [ Sat Oct 06, 2007 7:34 pm ]
Post subject:  RE:need help with returning variables

Do you know what "void" means?

Author:  HeavenAgain [ Sat Oct 06, 2007 10:46 pm ]
Post subject:  RE:need help with returning variables

Java:

class Testing
{
  public static void main(String[] args)
  {
    String myName = vars();
    System.out.println(myName);
  }
  public static String vars()
  {
    return "Alan";
  }
}

Author:  Euphoracle [ Sat Oct 06, 2007 10:50 pm ]
Post subject:  RE:need help with returning variables

This is why I don't like the curriculum, they don't teach you any of the underlying concepts before teaching you the syntax. Our teacher says to us, and I quote: "You need to put public static void main( String args[] ) because you have to memorize it, without it you cannot write a program".

I mean seriously. Problems like this arise.

Author:  wtd [ Sun Oct 07, 2007 1:04 pm ]
Post subject:  RE:need help with returning variables

http://compsci.ca/v3/viewtopic.php?t=9576

Author:  shadowman571 [ Sun Oct 07, 2007 3:09 pm ]
Post subject:  Re: RE:need help with returning variables

Euphoracle @ Sat Oct 06, 2007 10:50 pm wrote:
This is why I don't like the curriculum, they don't teach you any of the underlying concepts before teaching you the syntax. Our teacher says to us, and I quote: "You need to put public static void main( String args[] ) because you have to memorize it, without it you cannot write a program".

I mean seriously. Problems like this arise.


that is what my teacher told me as well

and thankyou i understand now


: