Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 need help with returning variables
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
shadowman571




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Sat Oct 06, 2007 7:34 pm   Post subject: RE:need help with returning variables

Do you know what "void" means?
HeavenAgain




PostPosted: 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";
  }
}
Euphoracle




PostPosted: 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.
wtd




PostPosted: Sun Oct 07, 2007 1:04 pm   Post subject: RE:need help with returning variables

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




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: