Results 1 to 2 of 2
  1. #1
    georger55 is offline Member
    Join Date
    Jul 2012
    Rep Power

    Default Reversing an Array

    Java Code:
        public static void main(String[] args){
            Scanner input = new Scanner(;
            System.out.println("Welcome to the word reversing program");
            System.out.println("First you will enter a sentence and then the letters of each word will be in the reversed order");
            System.out.print("Please enter a Sentence: ");
            String original = input.nextLine();
            String reverse = wordReverse(original);
            List<String> nSentence = fixOrder(reverse);
            System.out.println("Reversing the words in the sentence: " + original + ", looks like: " + nSentence );
        public static String wordReverse(String original){
            StringTokenizer string = new StringTokenizer(original);
            Stack<Character> charStack = new Stack<Character>();
            while (string.hasMoreTokens()){
            String stack = string.nextToken();
            for (int i = 0; i < stack.length(); i ++){
            charStack.push(' ');
            StringBuilder result = new StringBuilder();
            return result.toString();   
        public static List<String> fixOrder(String reverse){
            List<String> list = Arrays.asList(reverse);
           return list;
    The code reads as everything is fine but the output is not reversed. If the input is "hello world" the output should be "olleh dlrow". The words are reversed to "dlrow olleh" in the word reverse method. I created a fixOrder method to reverse the order of the string so the output should be "olleh dlrow". Even with the reversal in the array i am still getting the output "dlorw olleh". Any suggestions?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

Similar Threads

  1. Reversing an array
    By severus1 in forum New To Java
    Replies: 12
    Last Post: 06-30-2011, 05:34 PM
  2. Array reverse algorithim - reversing elements
    By Adomini in forum New To Java
    Replies: 9
    Last Post: 08-30-2010, 04:13 AM
  3. Reversing the String
    By Inaam in forum New To Java
    Replies: 1
    Last Post: 03-30-2009, 08:35 PM
  4. Reversing
    By whosadork in forum New To Java
    Replies: 14
    Last Post: 11-06-2008, 04:29 AM
  5. reversing Strings
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-11-2007, 08:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts