Java Program to Reverse the Given String

Get a String and reverse the characters of the string

Sample Input 1:

Hello

Sample Output 1:

olleH

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

public class Hello { public static void main(String args[]) { //Write your code here } }

Program or Solution

				
			
					
//To Reverse The Given String...

import java.util.*;

class Program
{
  public static void main(String args[])
  {
    String str,str1=" ";
    int i;

   Scanner sc=new Scanner(System.in);

   System.out.println("Enter The String:");
   str=sc.next();

   int len=str.length();
   for(i=len-1;i>=0;i--)
    {
        str1=str1+str.charAt(i);
    }

   System.out.println("The Output Is:"+str1);
  }

}
			
				
			

Program Explanation

Comments