Q:

Write a Java program to reverse a string

0

Write a Java program to reverse a string
Input Data:
Input a string: The quick brown fox


Expected Output:

Reverse string: xof nworb kciuq ehT

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now