Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- 123 -> 1 + 2 + 3 = 6
- 476 -> 4 + 7 + 6 = 17
- 12333 -> 1 + 2 + 3 + 3 + 3 = 12
- 78 -> 7 + 8 = 15
- 91 -> 9 + 1 = 10
- 267 -> 2 + 6 + 7 = 15
- -1
- ОТВЕТ: 123 * 12333 * 91 = 138043269
- **/
- import java.util.Scanner;
- class Program {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int number = scanner.nextInt();
- int mult = 1;
- int currentSum = 0;
- while(number != -1) {
- // делаем копию числа
- int copyNumber = number;
- // посчитать сумму цифр
- while(number != 0) {
- // берем последнюю цифру
- int lastDigit = number % 10;
- // кидаем в сумму
- currentSum = currentSum + lastDigit;
- // отбрасываем последнюю цифру
- number = number / 10;
- }
- // если сумма цифр - четная
- if (currentSum % 2 == 0) {
- // кидаем в произведение
- mult = mult * copyNumber;
- }
- // сумму обнуляем
- currentSum = 0;
- // считываем следующее число
- number = scanner.nextInt();
- }
- System.out.println(mult);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement