string reversein java code example
Example 1: reverse string java
String string="whatever";
String reverse = new StringBuilder(string).reverse().toString();
System.out.println(reverse);
Example 2: string reverse in java
String str = "Hello";
String reverse(String str){
StringBuilder sb = new StringBuilder();
sb.append(str);
sb.reverse();
return sb.toString();
}
Example 3: reverse a string in java
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the String:");
char[] letters = input.nextLine().toCharArray();
System.out.println(" Reverse String");
for(int i = letters.length -1; i >= 0; i--){
System.out.print(letters[i]);
}
}
}