Write a program that reads a value of k from the keyboard and displays the value of M(k), which is computed by a recursive method.
Suppose we have a satellite in orbit. To communicate to the satellite, we can send messages composed of two signals: dot and dash. Dot takes 2 microseconds to send, and dash takes 3 microseconds to send. Imagine that we want to know the number of different messages, M(k), that can be sent in k microseconds.
• If k is 0 or 1, we can send 1 message (the empty message).
• If k is 2 or 3, we can send 1 message (dot or dash, respectively).
• If k is larger than 3, we know that the message can start with either dot or dash. If the message starts with dot, the number of possible messages is M(k - 2). If the message starts with dash, the number of possible messages is M(k - 3). Therefore the number of messages that can be sent in k microseconds is M(k - 2) + M(k - 3).
```
public static int messages(int time){
int result;
if(time <= 3)
result = 1;
else
result = messages(time - 2) + messages(time - 3);
return result;
}
```
This code is in Methods.java.
You might also like to view...
Theoretically, clients do not need to see the _________ of classes from which they derive other classes.
a. Header files. b. Source code. c. Object code. d. Interface.
To convert a string object that stores an integer to a variable of type int one can use the C++11 function ____________.
Fill in the blank(s) with the appropriate word(s).
What will be output from the following code:
Reports have ________ views
Fill in the blank(s) with correct word