Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a static method called weave that that takes two integers as parameters and that returns the result of weaving their digits together to form

Write a static method called weave that that takes two integers as parameters and that returns the result of weaving their digits together to form a single integer. Two numbers x and y are weaved together as follows. The last pair of digits in the result should be the last digit of x followed by the last digit of y. The second-to-the-last pair of digits in the result should be the second-to-the-last digit of x followed by the second-to-the-last digit of y. And so on.

For example, consider weaving 128 with 394. The last pair of digits in the result should be 84 (because the original numbers end in 8 and 4). The second-to-the-last pair of digits in the result should be 29 (because the second-to-the-last digits of the original numbers are 2 and 9). The third-to-the-last pair of digits in the result should be 13 (because the third-to-the-last digits of the original numbers are 1 and 3). Thus:

weave(128, 394);

should return 132984. Notice that the order of the arguments is important. The call weave(394, 128) would return 319248.

If one of the numbers has more digits than the other, you should imagine that leading zeros are used to make the numbers have equal length. For example, weave(2384, 12) should return 20308142 (as if it were a call on weave(2384, 0012)). Similarly, weave(9, 318) should return 30198 (as if it were a call on weave(009, 318)).

You may assume that the numbers passed to weave are non-negative. You may not use Strings to solve this problem; you must solve it using integer arithmetic.

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_2

Step: 3

blur-text-image_3

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

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions

Question

6. Is all Internet training the same? Explain.

Answered: 1 week ago