crackyourinterview.com


To improves our performance please Like Share Subscribe(Will boost us)

Write code to reverse a string in Java?
Question Posted on 06 Apr 2021Home >> 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



.


Most Visited Questions:-

Deep Learning Questions Answers
Below are the different Deep Leaning Questions and answer a More...

Continuous Integration Questions Answers
Below are the 20 odd questions for CI or Continuous Integra More...

Derived relationships in Association Rule Mining are represented in the form of __________.
Derived relationships in Association Rule Mining are repres More...

What is Gulpjs and some multiple choice questions on Gulp
Gulpjs is an open source whihc helps in building Javascript More...

Microservices Architecture Questions Answers
Below are the different questions on Microservices Architec More...




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






@2014-2022 Crackyourinterview (All rights reserved)
Privacy Policy - Disclaimer - Sitemap