1

Hello I have the following string but cant seem to get it to display the word entered in original form as well as its reverse form together.

NameemaN

Can someone please help?

import java.util.*;

class ReverseString
{
   public static void main(String args[])
   {
      String Nombre, reverse = "";
      Scanner in = new Scanner(System.in);

      System.out.println("Anota tu Nombre");
      Nombre = in.nextLine();

      int length = Nombre.length();

      for ( int i = length - 1 ; i >= 0 ; i-- )
         reverse = reverse + Nombre.charAt(i);

      System.out.println("Tu nombre alrevez: " + reverse);
   }
}
  • 3
    Possible duplicate of [Reverse a string in Java](http://stackoverflow.com/questions/7569335/reverse-a-string-in-java) – wadda_wadda Nov 02 '15 at 00:50
  • 3
    @wadda_wadda I don't believe it is a dup as the OP is not asking for logic to reverse a string. – sam Nov 02 '15 at 00:53

1 Answers1

2

You're not printing it forward first so it will only print in reverse.

Try changing the print statement to...

System.out.println("Tu nombre alrevez: " + Nombre + reverse);

ChiefTwoPencils
  • 13,548
  • 8
  • 49
  • 75