Java Method For Reversing a Strings and Numbers

If you want to reverse a text or number just use the give code:

String rev( String string)
{

    String pro,temp="",rev=null;
    int len=string.length();
    int a=len-1;
   
for(int b=len;b>=1;b--){
    pro=string.substring(a , b);
    a--;
    rev=temp=temp+pro;
    }
return (rev);

}

Note: When you reverse the number, the above method gives output in string datatype so convert it use parse function.

Leave a Reply

Make sure you tick the "Notify Me" box below the comment form to be notified of follow up comments and replies.