Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help using a method
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
LOL123




PostPosted: 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
Sponsor
sponsor
wtd




PostPosted: Sun Apr 18, 2010 5:44 pm   Post subject: RE:Help using a method

The Introduction to Java covers methods extensively. It also has some things to say about naming conventions.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: