I am trying to reverse a String input by the user. I don't think I am far off but I have been stuck for awhile and can't figure out a solution.[Disallowed URL]


1 2 3 4 5 6 7 8 9 10 11 12 13 | public void act() { String user=Greenfoot.ask( "Input a word or phrase" ); int index= 0 ; while (index>=-user.length()- 1 ) { showText(user.substring(-user.length(),user.length()), 300 , 200 ); index=index- 1 ; } Greenfoot.stop(); } |
1 2 3 4 5 6 7 8 9 10 11 | public void act() { String user = Greenfoot.ask("Input a word or phrase); if (user != null ) { StringBuilder sb = new StringBuilder(user); sb.reverse(); showText(sb, 300 , 200 ); } Greenfoot.stop(); } |