Question
I need a help in writing a program in java. A positive base-8 integer is an integer that consists of the digits 1 through 7.
I need a help in writing a program in java.
A positive base-8 integer is an integer that consists of the digits 1 through 7. The right-most digit is in the 1s place. The digit n places from the right is in the 8n place. For instance, 70120 = 784 + 083 + 182 + 281 +080. An array can be used to store base-8 integers one digit at a time. For example, the base-8 integer 5336 could be stored in the array num by setting num[0] to 6, num[1] to 3, num[2] to 3, and num[3] to 5. Notice that the digit in the ones place is stored in num[0]. Write a program that reads in two positive base-8 integers with no more than 30 digits and then outputs the sum of the numbers. Read the users entry as a String and then convert the String to the array described above. Youre not required to implement error handing. Therefore, assume the users entries only contains the digits 1 through 7. This program should implement the usual paper-and-pencil addition algorithm. The result should be stored in an array with 30 elements, and the result should then be written to the screen. For example, if the user enters 173 and 5010, you would display 173 + 5010 = 5203. If the result of the addition is a base-8 integer with more than the 30 digits, then your program should issue a message that it has encountered integer overflow. Include a loop that allows the user to perform additions until the user says the program should end. (Hint: use a while loop or a do-while loop.) Make sure to test your code for additions that do not generate overflow and additions that do generate overflow.
Sample Output: Example 1 If the user enters 10717 and 111 the program should display the following output. 10717 + 111 = 11030 Example 2 If the user enters 700000000000000000000000000000 and 100000000000000000000000000000 then the program should display the following output. 700000000000000000000000000000 + 100000000000000000000000000000: overflow
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started