Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- int number=0, result=0;
- boolean isIncorrect;
- Scanner in = new Scanner(System.in);
- do {
- isIncorrect = false;
- try {
- System.out.println("Введите натуральное число: ");
- number = Integer.parseInt(in.nextLine());
- }
- catch (Exception e) {
- System.err.println("Неверный ввод данных!");
- isIncorrect = true;
- }
- } while (isIncorrect);
- while (number > 10) {
- result = (number % 10) + result;
- number = number / 10;
- }
- result = result + number;
- System.out.print("Сумма цифр данного числа: ");
- System.out.println(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement