
-----------------------------------
whoareyou
Tue Apr 19, 2011 3:09 pm

help - reversing string input
-----------------------------------
This "test" program is supposed to output a string that was inputted in reverse order. I can get it working, except it won't show the first letter. For example, if the string I input is "Hello", it outputs "olle". That's the first problem. The second problem is that when I set up a for loop to count from the last letter to the first, it displays a weird error message.

[code]
java.lang.StringIndexOutOfBoundsException: String index out of range: 5
        at java.lang.String.charAt(Unknown Source)
        at Lool.main(Lool.java:26)
[/code]

This is the actual code. 

[code]

// The "Lool" class.
import java.awt.*;
import hsa.Console;

public class Lool
{
    static Console c;           // The output console

    public static void main (String[] args)
    {
        c = new Console ();

        String str;

        c.println ("Please type a sentence: ");
        str = c.readLine ();



        c.println (str);

        for (int i = str.length (); 0