This question is not related to swapping, but it is a good one nonetheless.) Usi
ID: 3669748 • Letter: T
Question
This question is not related to swapping, but it is a good one nonetheless.) Using any of the methods of the NaturalNumber component family, implement the method specified as follows:
1
2
3
4
5
6
7
8
9
/**
* Squares a given {@code NaturalNumber}.
*
* @param n
* the number to square
* @updates n
* @ensures n = #n * #n
*/
private static void square(NaturalNumber n) {...}
Be careful when handling references.
1
2
3
4
5
6
7
8
9
/**
* Squares a given {@code NaturalNumber}.
*
* @param n
* the number to square
* @updates n
* @ensures n = #n * #n
*/
private static void square(NaturalNumber n) {...}
Explanation / Answer
public class Main {
/**
* Squares a given {@code NaturalNumber}.
*
* @param n
* the number to square
* @updates n
* @ensures n = #n * #n
*/
private static void square(NaturalNumber n) {
n.multiply(n);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.