Take FREE!! Online Mettl Mock Test to Crack TechM and Other Companies Written Exams.
Get Off-Campus Placement Jobs Info !!!
TCS NQT Technical and Managerial Round Interview Questions

Program Discussion :: Strings

Home > Programs > Strings

40 / 59

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: