Posted: Sun Apr 18, 2010 2:44 pm Post subject: 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);
}
}
As I stated before I only need help to get my method working, that you for your time.
Sponsor Sponsor
wtd
Posted: Sun Apr 18, 2010 5:44 pm Post subject: RE:Help using a method