Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

  1. Convert x to base 8, call this p
  2. Sort the digits of p in increasing order, call this q
  3. Subtract q from p in octal (convert q and p to decimal, subtract and convert back to octal)
  4. Repeat steps 2 - 3, four more times or until the digits in the result are in sorted order.
  5. 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:

  1. 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}

  1. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Structures and Algorithm Analysis in Java

Authors: Mark A. Weiss

3rd edition

132576279, 978-0132576277

More Books

Students also viewed these Programming questions