Q #1) Write a Java Program to reverse a string without using String inbuilt function reverse().

class ReverseStringWithoutFunction
 {
 public static void main(String… s)
 {
   String st1="TEST1";
   char ch[]=st1.toCharArray(); // convert string in to char type array
 /* char[] = String.toCharArray() method return a char[] array */
 for(int i=(ch.length-1);i>=0;i--) //start loop char[] type array length and -1 because loop start position 0
   {
     System.out.print(ch[i]);
   }
 }
 }

Result :- 1TSET

Leave a Reply

Your email address will not be published. Required fields are marked *