java reverse the letters code example

Example 1: how to reverse a string in java

public class ReverseString {
    public static void main(String[] args) {
        String s1 = "neelendra";
        for(int i=s1.length()-1;i>=0;i--)
            {
                System.out.print(s1.charAt(i));
            }
    }
}

Example 2: reverse a string in java

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]);
        }
    }
}