Advertisement
CR7CR7

digits

Jun 12th, 2023
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4. public class CrockedNumberVar2Dgudj {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         String input = scanner.nextLine();
  8.         String textNumber = input.replace("-", ""); // Remove the negative sign if present
  9.  
  10.         BigInteger currentNumberSum = BigInteger.ZERO;
  11.         BigInteger bigIntegerSumDigits2 = BigInteger.ZERO;
  12.  
  13.         for (int i = 0; i < textNumber.length(); i++) {
  14.             BigInteger tempDigit = BigInteger.valueOf(Character.getNumericValue(textNumber.charAt(i)));
  15.             currentNumberSum = currentNumberSum.add(tempDigit);
  16.         }
  17.  
  18.         BigInteger sumDigits = currentNumberSum.add(BigInteger.valueOf(Character.getNumericValue(textNumber.charAt(textNumber.length() - 1))));
  19.  
  20.         String textNumberSumDigits = sumDigits.toString();
  21.  
  22.         for (int i = 0; i < textNumberSumDigits.length(); i++) {
  23.             BigInteger tempDigit2 = BigInteger.valueOf(Character.getNumericValue(textNumberSumDigits.charAt(i)));
  24.             bigIntegerSumDigits2 = bigIntegerSumDigits2.add(tempDigit2);
  25.         }
  26.  
  27.         System.out.println(bigIntegerSumDigits2);
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement