IsNumberDividesBy3. 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. Answer to the question whether a given number is divisible by 3. The program does the following:
- Prompts the user for an integer.
- Sets the sum of digits variable to zero.
- Creates a temporary variable with an initial a positive value equal in magnitude to the number entered from the keyboard.
- 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.
- It is checked whether the resulting sum of the digits of the number is divisible by 3.
- The entered number and the sum of its digits are displayed on the screen.
- The answer to the question whether the given number is divisible by 3 is displayed on the screen.
IsNumberDividesBy3. Занятия по Java. Консольное приложение. Простой Ввод/вывод. Алгоритмы. Проект консольного приложения написан на языке программирования Java и реализован в интегрированной среде Apache NetBeans. Платформа Java. Простой ввод-вывод. Определение суммы цифр в числе, введённом с клавиатуры. Ответ на вопрос делится ли данное число на 3. Данная программа делает следующее:
- Запрашивает у пользователя ввод целого числа.
- Устанавливает переменную суммы цифр в значение равное нулю.
- Создаёт временную переменную с первоначальным положительным значением равным по модулю числу введённому с клавиатуры.
- Выполняется цикл с предусловием: a) Значение переменной сравнивается с нулём. Если оно больше нуля, цикл продолжает выполняться, в противном случае завершается (Переход к пункту 5). b) Сумма цифр увеличивается на остаток от деления значения временной переменной на 10. c) Времменая переменная делится на 10
- Проверяется делится ли полученная сумма цифр числа на 3.
- На экран выводится введённое число и сумма его цифр.
- На экран выводится ответ на вопрос делится ли данное число на 3.