Created
April 8, 2017 15:30
-
-
Save aalonzolu/e03d1911d5dc3b096a37ed6336004cd7 to your computer and use it in GitHub Desktop.
Java reverse string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package reverse.string.app; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
while (true) { /// ejecutar siempre el script | |
System.out.println("Ingrese un Nombre");// imprimir instrucciones | |
Scanner hola = new Scanner(System.in); // crear objeto scanner en hola | |
String mundo= hola.nextLine(); // obtener entrada de texto y guardarlo en mundo | |
int tamano = mundo.toCharArray().length; // convertir el texto a arreglo y obtener su tamaño | |
for (int i =tamano;i>0;i--){ // recorrer desde el tamaño hasta 0 | |
char letra = mundo.toCharArray()[i-1]; // imprimir una letra con indice i-1 | |
System.out.print(letra); // imprimir letra | |
} | |
System.out.println(); // imprimir un enter | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment