string reverse implementation code example

Example 1: reverse a string in java using input

public class Main {

    public static void main(String[] args) {
	// Write a Java program to reverse a string.
        Scanner input = new Scanner(System.in);
        System.out.println("Enter the String:");
        char[] letters = input.nextLine().toCharArray();
        System.out.println(" Reverse String");
        for(int i = letters.length -1; i >= 0; i--){
            System.out.print(letters[i]);
        }
    }
}

Example 2: code to reverse a string

#include <stdio.h>
#include <string.h>
int main()
{
   char s[100];

   printf("Enter a string to reverse\n");
   gets(s);

   strrev(s);

   printf("Reverse of the string: %s\n", s);

   return 0;
}

Tags:

C Example