Question
Consider the method reverse (as defined below), which reverses the digit of a given NaturalNumber . For example, if the initial value of n is
Consider the method reverse (as defined below), which reverses the digit of a given NaturalNumber . For example, if the initial value of n is 346, after it will be 643. /** * Reverses the digits in NaturalNumber n. * * @updates n * @requires [none of the digits in n is 0] * @ensures n = [#n with its digits reversed] */ private static void reverse(NaturalNumber n) { } 1. Implement this method without using recursion. You can only use kernel methods (including Standard methods), and you are not allowed to use any other reference types besides NaturalNumber (so no arrays, Strings, etc.). 2. Implement this methods using recursion. You may use non-kernel methods, but you are still restricted from using any other reference types besides NaturalNumber . You may write additional helper methods that you can call inside your implementation, but they must obey all the same restrictions above. If you write helper methods, include full JavaDoc contracts for them.
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