Friday, February 13, 2009

Reverse Of a String

/*Reverse Of a String */

class reverse
{
public void reverse123(String str)
{
String str1="";
for(int i=str.length()-1;i>=0;i--)
{
str1=str1+str.charAt(i);
}
System.out.print(str1);
}
}
public class reverse_string {
public static void main(String args[])
{
reverse obj=new reverse();
obj.reverse123("Bangalore");
}
}

1 comment:

  1. Hi uday,

    This program will throw an error. Just above the main function. I tried executing the same program but gave me error. So I have modified the same program and posting it.
    Here's the program :
    /*Reverse a String*/

    package reverse;

    public class Reverse {
    public void reverse(String str)
    {
    String str1="";
    for(int i=str.length()-1;i>=0;i--)
    {
    str1=str1+str.charAt(i);
    }
    System.out.print(str1);
    }



    public static void main(String args[])
    {
    Reverse obj=new Reverse();
    obj.reverse("Bangalore");
    }
    }

    ReplyDelete