Question: Write a program that prompts the user to enter two positive whole numbers as strings! Create a method that validates the input and returns true
Write a program that prompts the user to enter two positive whole numbers as strings! Create a method that validates the input and returns true if all chars in the string are digits. Call the method from the main and prompt the user to re-enter as long as invalid input was entered. Create a second method that converts the string to an int and returns it. Use a loop to iterate over each char in the string. You can convert a char c to an int by subtracting the char 0 from it: int num = (int)ch - '0'; Add the digit to a result variable and multiply the result with each iteration by 10, for example: 4127 can be split up as 4 * 1000 + 1 * 100 + 2 * 10 + 7 * 1 The program then converts both strings to integers and computes and prints out the sum. When you are printing the sum. Make another method named usingAPI that does convert "5555" to int 5555 using java API.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
