public class Practice01{ public static String reverse(String input) { char[] chars = input.toCharArray(); for(int i = 0, j = input.length() - 1; i < j; i++, --j) { char t = chars[i]; chars[i] = chars[j]; chars[j] = t; } return new String(chars); } }
//import java.util.Scanner;- 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);- char[] chars = input.toCharArray();
- for(int i = 0, j = input.length() - 1; i < j; i++, --j) {
- char t = chars[i];
- chars[i] = chars[j];
- chars[j] = t;
- }
return result;- return new String(chars);
- }
- }
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); } @Test public void test() { testing("!ereht olleH" , Practice01.reverse("Hello there!")); testing("\uFFFF\uFFFE\uFFFD\uFFFC", Practice01.reverse("\uFFFC\uFFFD\uFFFE\uFFFF")); testing("", Practice01.reverse("")); } }
- 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);
- }
- @Test
- public void test() {
- testing("!ereht olleH" , Practice01.reverse("Hello there!"));
- testing("\uFFFF\uFFFE\uFFFD\uFFFC", Practice01.reverse("\uFFFC\uFFFD\uFFFE\uFFFF"));
- testing("", Practice01.reverse(""));
- }
- }