Java program Research
Java program Research
Program 1 Algorithm
Problem statement:
Write a Java program to add up the digits of a number entered by the user and output the result. You may not use an array top perform this task. The program should be able to handle an integer of any size.
For example, if the number 1256 was entered, the sum would be:
SumOfDigits = 1 + 2 + 5 + 6 = 14
Solution:
The following Algorithm could be used:
Define variables
Get input number
Get each digit of input number
Add digit to sumOfDigits
Output sumOfDigits
loop
remainder = inputNumber % 10
sumOfDigits = sumOfDigits + remainder
inputNumber = inputNumber – remainder
inputNumber = inputNumber / 10
end loop
Some helpful code snippets:
To get length of input number
int lenOfNum = String.valueOf(inputNum).length();
To get number from keyboard
int inNumber = Integer.parseInt(s.nextLine()); // What about validating input?
Using the files from the in-class assignment add two additional animals of your choice. For each animal add two additional methods appropriate to your particular animal.
As the majority of the code for this program exists you will not need an algorithm.
please use the code that i have in my question
We can write this or a similar paper for you! Simply fill the order form!