Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- import java.util.Scanner;
- public class CrockedNumberVar2Dgudj {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- String textNumber = input.replace("-", ""); // Remove the negative sign if present
- BigInteger currentNumberSum = BigInteger.ZERO;
- BigInteger bigIntegerSumDigits2 = BigInteger.ZERO;
- for (int i = 0; i < textNumber.length(); i++) {
- BigInteger tempDigit = BigInteger.valueOf(Character.getNumericValue(textNumber.charAt(i)));
- currentNumberSum = currentNumberSum.add(tempDigit);
- }
- BigInteger sumDigits = currentNumberSum.add(BigInteger.valueOf(Character.getNumericValue(textNumber.charAt(textNumber.length() - 1))));
- String textNumberSumDigits = sumDigits.toString();
- for (int i = 0; i < textNumberSumDigits.length(); i++) {
- BigInteger tempDigit2 = BigInteger.valueOf(Character.getNumericValue(textNumberSumDigits.charAt(i)));
- bigIntegerSumDigits2 = bigIntegerSumDigits2.add(tempDigit2);
- }
- System.out.println(bigIntegerSumDigits2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement