Sunday, February 12, 2017

Java program to enter an string and reverse it.

import java.io.Console;
class ReverseString
{
public static void main(String[] args)
{
Console c=System.console();
String s=c.readLine("Enter String to reverse : ");
String rev="";
for(int i=s.length()-1;i>=0;i--)
rev=rev+s.charAt(i);
System.out.println("Original String = "+s);
System.out.println("Reversed String = "+rev);
}
}

Share this

0 Comment to "Java program to enter an string and reverse it."

Post a Comment