India’s Best Job Seekers and Training Platform › Forums › Java Problems set › Reverse the string..
-
Write a program to reverse the string.
-
import java.util.Scanner;
public class ReverseString{
public static void main(String []args){
Scanner Scan=new Scanner(System.in);
System.out.println(“Enter the string which is to be reversed “);
String str=Scan.nextLine();
String rev=””;
for(int i=str.length()-1;i>=0;i–){
rev=rev+str.charAt(i);
}
System.out.println(“The reversed string is “+rev);
}
}
Log in to reply.