Question: Write a class named duplicate that use a method named duplicateDigits long duplicateDigits ( long n ) that, given a long integer n that is

Write a class named duplicate that use a method named duplicateDigits
long duplicateDigits(long n)
that, given a long integer n that is here guaranteed to be positive, returns the integer
constructed by writing its digits twice in a row.
For example, when called with argument 1504, this method would return 15041504. You
may not convert n to a string at any time, but must calculate the answer using only loops,
conditions and basic integer arithmetic.
Your method must work correctly for all positive values of n less than one million. (Hint: think
of how you would check whether n consists of one digit, and how you would calculate the
duplicated number in such case. Then think of two digits, three digits, four digits and higher
until you can see and can implement the general pattern.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!