-
Code //import java.util.Scanner; import java.lang.StringBuilder; public class Practice01{ public static String reverse(String input) { /*Scanner sc = new Scanner(System.in); System.out.println("Give the desired string to be reversed :"); String e = sc.nextLine();*/ return new StringBuilder(input).reverse().toString(); } }
Test Cases import static org.junit.Assert.*; import org.junit.Test; // TODO: Replace examples and use TDD by writing your own tests public class Practice01Test { private static void testing(String actual, String expected) { assertEquals(expected, actual); } public void test() { testing("!ereht olleH" , Practice01.reverse("Hello there!")); } }
Output:
-
Code - //import java.util.Scanner;
- import java.lang.StringBuilder;
- public class Practice01{
- public static String reverse(String input) {
- /*Scanner sc = new Scanner(System.in);
- System.out.println("Give the desired string to be reversed :");
- String e = sc.nextLine();*/
String result = "";for(int i = input.length() - 1; i >= 0; i --){result += input.substring(i , i + 1);}return result;- return new StringBuilder(input).reverse().toString();
- }
- }
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}