Question
Octonumero (ver 2) An octonumero of a number x is found as follows. Convert x to base 8, call this p Sort the digits of
Octonumero (ver 2)
An octonumero of a number x is found as follows.
- Convert x to base 8, call this p
- Sort the digits of p in increasing order, call this q
- Subtract q from p in octal (convert q and p to decimal, subtract and convert back to octal)
- Repeat steps 2 - 3, four more times or until the digits in the result are in sorted order.
- Convert the number back to decimal
Example:
x = 341810
convert: 341810 = 65328
sort and subtract: 65328 - 23568 = 41548
4 more times: 41548 - 14458 = 25078
3 more times: 25078 - 2578 = 2230,
2 more times: 22308 - 2238 = 20058
last time: 20058 - 258 = 17608
convert: 17608 = 100810
I need help with the following methods, please:
- public static int[] numToArray (int num)
//Precondition: 999 < num < 10000. Assume num is a 4 digit number
numToArraywill place every digit of num as an element of an array
For example, int [] digits = numToArray(2534)will result in an array calleddigits that contains{ 2, 5, 3, 4}
- public static int[] sortArray (int[] unsorted)
sortArraywill return an array in ascending order.
For example, if digits contains { 2, 5, 3, 4 } a call to int[] sorted = sorted(digits)will result in an array calledsortedthat contains
{ 2, 3, 4, 5 }.
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