Java Program to Reverse a String

  public class Practice_Vivek {

public static String Str=null;

public static void main(String[] args)
{
Str="Vivek Kaushik";
Practice_Vivek p1=new Practice_Vivek();
String reverse=p1.Reverse_string(Str);
System.out.println("string is " + reverse);
System.out.println("Program has run");
}
public String Reverse_string( String source)
{
String reverse="";
{
for(int i=Str.length()-1; i>=0;i--)
{
reverse=reverse + Str.charAt(i);

}

return reverse;
}
}
    }
    

No comments:

Post a Comment