I'm new to Java and I want to know if this code is efficient, and if there a shorter and faster way to reverse a string.
package Excercises;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Please enter a string you want to reverse: ");
String text = scan.next();
String[] letters = text.split("");
char[] reversed = new char[letters.length];
int c = letters.length - 1;
for(String s : letters) {
reversed[c] = s.charAt(0);
c = c - 1;
}
System.out.println(new String(reversed));
}
}
reverse
may not be used. \$\endgroup\$