Sentence Reverse Program in Java

Sentence Reverse Program in Java
Sentence Reverse Program in Java

Enter a sentence or string and print its reverse string in java.

import java.util.Scanner;

/**
 *
 * @author AFAQ
 */
public class SentenceReverse
{
    public static void main(String[] args)
    {
        String st,revSt="";
        int l;
        Scanner sc=new Scanner(System.in);
        
        System.out.print("Enter String:");
        st=sc.nextLine();
        l=st.length();
        for (int i = l-1; i >= 0; i--)
        {
            char ch;
            ch=st.charAt(i);
            revSt=revSt+ch;
        }
        System.out.println("Reverce String:"+revSt);
    }
}

Output:

Enter String:this is a boy
Reverce String:yob a si siht
java tutorials learn java study java