Q1. Can you write a method that reverses a given String? A1. Can be done a number of different ways. Best Practice: Using the Proven Java API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
public class ReverseString { public static void main(String[ ] args) { System.out.println(reverse("big brown fox")); System.out.println(reverse("")); } public static String reverse(String input) { if(input == null || input.length( ) == 0){ return input; } return new StringBuilder(input).reverse( ).toString( ); } } |
It is always a best practice to reuse the API methods as…