Reverse a string means rearrange the characters of a string in such a way that it’s first character becomes the last character , the second character becomes the second last, third character becomes the third last and so on .
Examples :
Input : String str=”Giftisincredible”
Output : “elbidercnisitfiG”
public class ReverseString{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println(“Enter a String you want to reverse”);
String str=sc.nextLine();
String reverse=” “;
int length=str.length();
for(int i=length-1;i>0;i–){
reverse=reverse+str.charAt(i);
}
System.out.println(“Reverse String is:”+reverse);
}
}
