Source Code
import java.util.Scanner;class ReverseString{
public void stringReverse(){
System.out.println("Enter string to reverse:");
Scanner read = new Scanner(System.in);
String str = read.nextLine();
StringBuilder sb = new StringBuilder();
for(int i = str.length() - 1; i >= 0; i--)
{
sb.append(str.charAt(i));
}
System.out.println("Reversed string is:");
System.out.println(sb.toString());
}
}
class Main{
public static void main(String[] args)
{
ReverseString obj=new ReverseString();
obj.stringReverse();
}
}
No comments: