1. (50pts) Two integer-valued functions F(n) and M(n) are recursively defined on nonnegative integers as follows: F(0)=1, M(0)=0, F(n)=n-M(F(n-1)) when n>0, M(n)=n-F(M(n-1)) when n>0.Write a complete...

1 answer below »
Can you finish this in 1 hour and 30 minutes?


1. (50pts) Two integer-valued functions F(n) and M(n) are recursively defined on nonnegative integers as follows: F(0)=1, M(0)=0, F(n)=n-M(F(n-1)) when n>0, M(n)=n-F(M(n-1)) when n>0.Write a complete Java program E2p1.java employing recursion to print the values of F(0), F(1),…, F(100) and M(0), M(1), …, M(100). 2. (50pts) Write a complete Java program E2p2.java to display to stdout the middle-third of the contents of a user-specified file byte by byte in hexadecimal format. The name of the file should be provided by the user as the first command line argument to your program. For example, if that file has size 60 bytes, your program should display the 20 bytes in the middle of the file (i.e. not display the first 20 bytes nor display the last 20 bytes). Each line should display 10 bytes with appropriate separators among them except possibly the last line. 3. (Optional extra credit 20pts) This question tests your understanding about base cases of recursion. In homework 4 you have been asked to write a program employing recursion to compute the function value p(N,k,l,s) and display it to stdout. The integer-valued function p(N,k,l,s) is defined on all integral 4-tuples (N,k,l,s) as follows: Is there anything unusual, if any, in the definition of p(N,k,l,s) that you feel might make your program run into problems for some given input tuple N,k,l,s (e.g. it never stops, it encounters java.lang.StackOverflowError exception)? Give justifications. You may answer “nothing unusual” if you did not find anything. Note: save your code into separate source files with appropriate name and file extensions (e.g. .java) and submit those source files into the dropbox folder. If you answer question 3, you can put your answer in this Word document and submit it or at the beginning of E2p1.java as a comment.
Answered Same DayMar 31, 2021

Answer To: 1. (50pts) Two integer-valued functions F(n) and M(n) are recursively defined on nonnegative...

Arun Shankar answered on Mar 31 2021
132 Votes
class E2p1
{
public static int M(int n)
{
if(n==0)
return 0;
return (n-F(M(n
-1)));
}
public static int F(int n)
{
if(n==0)
return 1;
return (n-M(F(n-1)));
}
public static void main(String[] args)
{
System.out.println("Printing F...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here