Java program to reverse a String without using direct method.
import java.io.BufferedReader;
public class ReverseOfString {
public static String reverseString(String s)
{
int l = s.length();
String backward = "";
for (int i = l - 1; i >= 0; i--)
{
backward = backward + s.charAt(i);
}
return backward;
}
public static void main(String args[]) {
String backwards = reverseString("Umesh Kushwaha");
System.out.println("Reverse String is " + backwards);
}
}
Output:
Reverse String is ahawhsuK hsemU
public class ReverseOfString {
public static String reverseString(String s)
{
int l = s.length();
String backward = "";
for (int i = l - 1; i >= 0; i--)
{
backward = backward + s.charAt(i);
}
return backward;
}
public static void main(String args[]) {
String backwards = reverseString("Umesh Kushwaha");
System.out.println("Reverse String is " + backwards);
}
}
Output:
Reverse String is ahawhsuK hsemU
Java Resources are available for Download from below
Category: Core Java, Interview, Programs, String, Written Test
0 comments