Hi Guest

MobileUser

1 HomePage 1 Jobs 1 WalkIn 1Articles  

Cat Exam

 :) Latest Topic
general knowledge
VB.NET
SQL Query
UDDI
CLASS
JavaScript Questions
SharePoint Interview
SilverLight
WCF
beans
 ASP.NET
 :) Hot Jobs
 
 :) Latest Articles


  

 
DogFood


Write code to reverse a string in Java?
Question Posted on 06 Apr 2021

Home >> Java >> Core Java >> Write code to reverse a string in Java?




Write code to reverse a string in Java?
Below is the code to reverse string in Java below code will helps you on that:-

public class StringReverseClass
{
  public static void main(String args[])
  {
   String str = "Crackyourinterview";
   String reverse = new StringBuffer(str).reverse().toString();
   System.out.printf("Word Enter: %s, Word after Reverse %s", str, reverse);
  }

  public static String reverse(String source)
  {
   if (source == null || source.isEmpty())
   {
    return source;
   }
   String reverse = "";
   for (int i = source.length() - 1; i >= 0; i--)
   {
    reverse = reverse + source.charAt(i);
   }
  return reverse;
  }
}

Output:-
Word Enter: Crackyourinterview, Word after Reverse weivretniruoykcarC
0
0



 
 Input Your Comments Or suggestions(If Any)
 Name
 Email(optional)
 Comments


Other Important Questions
what is an object
what is OOAD
difference between c++ and java
what is a transient variable in java
difference between C and Java on pointers






 
Top Searches:asp net questions vb net questions sql query uddl questions class javascript Questions sharepoint interview questions and concept silverlight questions and concept wcf questions beans general knowledge ajax questions
PHP | Biztalk | Testing | SAP | HR |