
-----------------------------------
LOL123
Sun Apr 18, 2010 2:44 pm

Help using a method
-----------------------------------
Hello 
I need to make a program that will take as input a word. The program will call a method to reverse the word, the method will return the word to the main program.
I had no problem creating a program that will reverse the word, but I dont understand how to code a method. The method must be in a diffrent java file from the main program the main program will call the method using an object with the input word as a parameter.
Here is my code:
[code]
import java.io.*;
class reverse_method
{
  public static void main(String[] args) 
    throws java.io.IOException
  {
    BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
    
    String input = " ";
    
    System.out.println ("Please enter a word:");
    input = br.readLine();
    int len = input.length();       
    char[] tempCharArray = new char[len];
    char[] charArray = new char[len];
    
    for (int i = 0; i < len; i++) {
      tempCharArray[i] = input.charAt(i);
    } 
    for (int j = 0; j < len; j++) {
      charArray[j] = tempCharArray[len - 1 - j];
    }
    String reverseWord =  new String(charArray);
    System.out.println(reverseWord);
  }
}
[/code]

As I stated before I only need help to get my method working, that you for your time.

-----------------------------------
wtd
Sun Apr 18, 2010 5:44 pm

RE:Help using a method
-----------------------------------
The [url=http://wiki.compsci.ca/index.php?title=Introduction_To_Java]Introduction to Java [url=http://wiki.compsci.ca/index.php?title=Introduction_To_Java#Creating_our_own_method]covers [url=http://wiki.compsci.ca/index.php?title=Introduction_To_Java#Methods_that_return_useful_values]methods [url=http://wiki.compsci.ca/index.php?title=Introduction_To_Java#Non-static_methods]extensively.  It also has some things to say about [url=http://wiki.compsci.ca/index.php?title=Introduction_To_Java#On_naming]naming conventions.
