Skip to content

Latest commit

 

History

History
27 lines (26 loc) · 2.63 KB

File metadata and controls

27 lines (26 loc) · 2.63 KB

SumOfDigits. Java tutorials. Console Application. Simple Input/Output. Algorithms. A console application project written in the Java programming language and implemented in the Apache NetBeans integrated environment. The Java platform provides simple input/output. Determining the sum of digits in a number entered from the keyboard. The program does the following:

  1. Prompts the user for an integer.
  2. Sets the sum of digits variable to zero.
  3. Creates a temporary variable with an initial a positive value equal in magnitude to the number entered from the keyboard.
  4. The loop with precondition is executed: a) The value of the temporary variable is compared to zero. If its value is greater than zero, the loop continues executing; otherwise, it terminates. (Go to step 5) b) The sum of digits variable is incremented by modulo to 10. c) The temporary variable is divisible by 10.
  5. The entered number and the sum of its digits are displayed on the screen.

SumOfDigits. Занятия по Java. Консольное приложение. Простой Ввод/вывод. Алгоритмы. Проект консольного приложения написан на языке программирования Java и реализован в интегрированной среде Apache NetBeans. Платформа Java. Простой ввод-вывод. Определение суммы цифр в числе, введённом с клавиатуры. Данная программа делает следующее:

  1. Запрашивает у пользователя ввод целого числа.
  2. Устанавливает переменную суммы цифр в значение равное нулю.
  3. Создаёт временную переменную с первоначальным положительным значением равным по модулю числу введённому с клавиатуры.
  4. Выполняется цикл с предусловием: a) Значение переменной сравнивается с нулём. Если оно больше нуля, цикл продолжает выполняться, в противном случае завершается (Переход к пункту 5). b) Сумма цифр увеличивается на остаток от деления значения временной переменной на 10. c) Времменая переменная делится на 10
  5. На экран выводится введённое число и сумма его цифр.