Write a Java program to reverse a stringInput Data:Input a string: The quick brown fox
Expected Output:
Reverse string: xof nworb kciuq ehT
import java.util.Scanner; public class Exercise37 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Input a string: "); char[] letters = scanner.nextLine().toCharArray(); System.out.print("Reverse string: "); for (int i = letters.length - 1; i >= 0; i--) { System.out.print(letters[i]); } System.out.print("\n"); } }
Sample Output:
Input a string: The quick brown fox Reverse string: xof nworb kciuq ehT
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer