Skip to content

Instantly share code, notes, and snippets.

@gitaficionado
Created November 6, 2019 05:50
Show Gist options
  • Save gitaficionado/fca0398b53a313f2af188fa470240212 to your computer and use it in GitHub Desktop.
Save gitaficionado/fca0398b53a313f2af188fa470240212 to your computer and use it in GitHub Desktop.
(Reverse a string) Write a program that prompts the user to enter a string and displays the string in reverse order.
import java.util.Scanner;
public class ReverseAStringExercise_05_46 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a string: ");
__________________________________
String result = "";
for (int i = __; ___ < s.length(); ____) {
result = s.charAt(i) + result;
}
System.out.println("The reversed string is " + result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment