Write a Java Program
Without using reverse Funtion?
import java.util.Scanner;
public class
ReverseStringWithoutReverseFunction {
public static String
reverse(String str) {
StringBuilder
sb = new StringBuilder();
char[] string = str.toCharArray();
for (int i = string.length - 1; i >= 0; i--) {
sb.append(string[i]);
}
System.out.println(sb.toString());
return sb.toString();
}
public static void main(String[] args) {
Scanner
keyboard = new Scanner(System.in);
System.out.println("Enter a
String:");
String
input = keyboard.next();
reverse(input);
}
}
No comments:
Post a Comment