How to writer String Reverse program without using any string libraries even length(), strrev().

Questions by molluru_mca

Showing Answers 1 - 13 of 13 Answers

chinnu

  • Nov 18th, 2006
 

hi,this is simple logic use charAt()in string class see here belowclass A1{public static void main(String args[]){String s1=" Jai Bharat Mahan";String s2="";for(int i=s1.length()-1;i>0;i--){ s2=s2+s1.charAt(i);}System.out.println("the reverse string is"+ s2);}}k te

  Was this answer useful?  Yes

public static void main(String args[])

{

String s1=" Mera Bharat Mahan";

String s2="";

int lenght = 0;

for(int i=0;s1.charAt(i) != null;i++) length++;

for(j=length; j<0;j++)

{ s2=s2+s1.charAt(j);}

System.out.println("the reverse string is"+ s2);

}

}

Y_NOT_

  • Feb 6th, 2007
 

public class ReverseString

{ public ReverseString()

{ String str = "Hello World";

StringBuffer buff = new StringBuffer( str );

buff.reverse(); System.out.println( "Reversed String: " + buff.toString() );

}

public static void main( String[] args )

{ new ReverseString();

}

}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions