/*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");
}
}
Subscribe to:
Post Comments (Atom)
Hi uday,
ReplyDeleteThis 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");
}
}