[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

Program Discussion :: Strings

Home > Programs > Strings

306 / 60

Write a program for string reverse without using the reverse function.

Answer:

import java.io.*;

public class ReverseString 
{
    public static void main(String[] args)throws IOException
    {    
        String str1="";
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter a String: ");
        String str=br.readLine();
        int len = str.length();
        for(int i=len-1;i>=0;i--)
        {
            char ch=str.charAt(i);
            str1=str1+ch;
        }
        System.out.println("Reverse string is: "+str1);
    }
}

Asked In ::

Post Your Answer Here:

Language:

Post Your Reply Here: