[hotjoe.com] HotJoe Java Help Forums
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Visit java.com
Missing post? - see this post about spam for more information.
Confusion on getting the value from a method in another method  XML
Forum Index » Java Programming
Author Message
Judy

Newbie

Joined: 02/04/2012 12:39:35
Messages: 1
Offline

So let's say I have a method that's scanning in the next word of a file from a scanner called (in) in the main method and just returning the String back to the main method. (I'm just trying to figure out how to get return values back before I get clever doing things in the other method.) When it comes back to the main method. I want to assign the returned value to a variable and print it out.
public static String othermethod (Scanner in)
{
String word = in.next ();
return word;
}
public static void main (String[] args)
{
// bunch of coding bringing in a scanner and reading the first word.

othermethod (in); // calling the other method which is to read the string and bring it back

// HOW DO I GET THE VALUE THE STRING IS RETURNING?

// My thought is to do something like...

String returnedvalue = othermethod();
System.out.println (returnedvalue);
}
// but it doesn't work with empty parameters and I'm not sure what I should be putting in the parameters.
Most of the things I've tried tell me that the String from my other method is not applicable to the arguments ()

Can anyone help me to understand this concept?
chowbaaron

1 cup a day
[Avatar]

Joined: 11/06/2011 20:53:10
Messages: 47
Location: New York, USA
Offline

I'm guessing what your saying is how do you input something in a method, then return it to the main? Your post is very unorganized and hard to read, I'm sorry to say.
Either way, this is how you would do what I said above:

This message was edited 3 times. Last update was at 02/06/2012 13:50:04

 
Forum Index » Java Programming
Go to:   
Powered by JForum 2.1.9 © JForum Team
This site run by Scott Dunbar of Xigole Systems. © 2005-2012 - Scott Dunbar
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners
hotjoe.com, xigole.com, and Scott Dunbar have no affiliation with Oracle