Made some simple tests.
public class Pratice01 { public static String reverse(String str) { return new StringBuilder(str).reverse().toString(); } }
import java.util.ArrayList;import java.util.Scanner;import java.util.Collections;public class Pratice01{public static void main(String[] args) {ArrayList<Character> arr = new ArrayList<>();Scanner sc = new Scanner(System.in);System.out.println("Give the desired string to be reversed :");String e = sc.nextLine();int f = e.length();for(int i= 0;i<f;i++){Character d = e.charAt(i);arr.add(d);}Collections.reverse(arr);String k = "";for(Character a:arr) {String p = k+a;String z = new StringBuilder().append(p).toString();System.out.print("Reversed string"+z);}}- public class Pratice01 {
- public static String reverse(String str) {
- return new StringBuilder(str).reverse().toString();
- }
- }
import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; // TODO: Replace examples and use TDD by writing your own tests class SolutionTest { @Test void testReverse() { assertEquals("olleh", Pratice01.reverse("hello")); assertEquals("detcepxe", Pratice01.reverse("expected")); assertEquals("0987654321", Pratice01.reverse("1234567890")); assertEquals("gnirtSecin", Pratice01.reverse("niceString")); assertEquals("eviFytroF", Pratice01.reverse("FortyFive")); assertEquals("Changes", Pratice01.reverse(Pratice01.reverse("Changes"))); } }
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- // TODO: Replace examples and use TDD by writing your own tests
- class SolutionTest {
- @Test
void testSomething() {// assertEquals("expected", "actual");- void testReverse() {
- assertEquals("olleh", Pratice01.reverse("hello"));
- assertEquals("detcepxe", Pratice01.reverse("expected"));
- assertEquals("0987654321", Pratice01.reverse("1234567890"));
- assertEquals("gnirtSecin", Pratice01.reverse("niceString"));
- assertEquals("eviFytroF", Pratice01.reverse("FortyFive"));
- assertEquals("Changes", Pratice01.reverse(Pratice01.reverse("Changes")));
- }
- }
Given a number, find the sum of its digits. Simple as that.
public class DigitSum {
public static int sumDigits(Long number) {
return number.toString().chars().map(ch -> Character.digit(ch, 10)).sum();
}
}
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
class SolutionTest {
@Test
void testSum() {
assertEquals(10, DigitSum.sumDigits(235L));
assertEquals(45, DigitSum.sumDigits(123456789L));
assertEquals(48, DigitSum.sumDigits(82586793L));
assertEquals(39, DigitSum.sumDigits(23851651053L));
assertEquals(0, DigitSum.sumDigits(000000L));
assertEquals(108, DigitSum.sumDigits(999999999999L));
assertEquals(91, DigitSum.sumDigits(59675697479612314L));
assertEquals(39, DigitSum.sumDigits(5962311048L));
}
}