Ad

Made some simple tests.

Code
Diff
  • 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();
    • }
    • }

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();
  }
}