aspose file tools*
The moose likes Beginning Java and the fly likes calling functions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "calling functions" Watch "calling functions" New topic
Author

calling functions

Daniel Hall
Greenhorn

Joined: Feb 18, 2002
Posts: 1
I just started programming and needed a little help. I am writing a program that reads in a number from a user then converts that number into a string(ex. 1 to one). I pass in the integer x now how do i return a string into a string variable called strx.
public static String wordNumber(int x)
if(x == 1)
return "one";

Shivaji Marathe
Ranch Hand

Joined: Jan 11, 2002
Posts: 203
You will nned to create a top-level class, declare this method in that class, and in the main method of that class, call this method.


HTH
Originally posted by Daniel Hall:
I just started programming and needed a little help. I am writing a program that reads in a number from a user then converts that number into a string(ex. 1 to one). I pass in the integer x now how do i return a string into a string variable called strx.
public static String wordNumber(int x)
if(x == 1)
return "one";

Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
It would be better to declare a local variable to be the string to return.
String returnString = "Some default verbage";
Then if you set up a Switch, in each case statement you can assign the correct word to the variable. At the end of the Switch you just return returnString. Having only one return is much easier for the next guy to follow, and prevents errors on your part.
 
 
subject: calling functions