codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  returning a value...  kunfusedenuf at 03:14 on Monday, September 12, 2005
 

hi all. i have an assignment for school that i'm having trouble with. i'm needing to return a value to main from a method. i need that value to equal a value in main. the value in the method is declared as a local variable. how do i call it in main? do i need to declare it again? i'm not sure.

  Re: returning a value...  crwood at 00:20 on Tuesday, September 13, 2005
 

You can save the string in a local variable inside the 'main' method if you need access to it later. Or you can call the method and use the return value without saving it.

class VariableTest
{
public static void main(String[] args)
{
// save return value in a variable
String s = getMessage();
System.out.println("s = " + s);

// use return value without saving it
System.out.println(getMessage());
}

private static String getMessage()
{
return "hello world";
}
}








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Date script issues
•  perl script help needed
•  onChange issue
•  perl remote execution
•  Chat application
•  How to send multiple perameters in SOAP request.
•  Java code for Insert picture on the table in spreadsheet
•  Re: Problem with concatenation
•  how to genrates the crystal report by sending a id at runtime


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007