Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in

Posted on

Invertir un string in Java

Invertir un string - Java:

public class InvertirString {
   * This method invert a string.
   * @param str String to invert.
   * @return String Obtains the inverted string.
   public String invertirString(String str) {
       //Variable to store the inverted string
       String inverted = "";
       //Invert the string
       for (int i = str.length()-1; i >= 0; i--) {
           inverted += str.charAt(i);
       //Return the inverted string
       return inverted;

   * One Example
   public static void main(String args[]) throws IOException {

      InvertirString  invertirString= new InvertirString ();
      String invertido = invertirString.invertirString("Hola Mundo");
      System.out.println("Inverted String is :" + invertido); //"odnuM olH"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)