1

1
mail@pastecode.io avatar
unknown
java
2 years ago
1.3 kB
2
Indexable
Never
        int srcNum = 781529;
        int digit1 = 0;
        int sumThreeNum = 0;
        int sumSecondThreeNum = 0;
        int firstPartNum = 0;
        int secondPartNum = 0;


        for (int i = 0; i < 6; i++) {
            digit1 = srcNum % 10;
            srcNum /= 10;
            
            if (srcNum / 100 != 0) {
                firstPartNum++;
                sumThreeNum += digit1;
                System.out.print(digit1);
                if (firstPartNum < 3) {
                    System.out.print(" + ");
                } else if (firstPartNum == 3) {
                    System.out.println(" = " + sumThreeNum);
                }
            } else {
                secondPartNum++;
                sumSecondThreeNum += digit1;
                System.out.print(digit1);
                if (secondPartNum < 3) {
                    System.out.print(" + ");
                } else if (secondPartNum == 3) {
                    System.out.println(" = " + sumSecondThreeNum);
                }
            }
        }
        if (sumThreeNum == sumSecondThreeNum) {
            System.out.println("Число является счастливым");
        } else {
            System.out.println("Число не является счастливым");
        }