Question

In: Computer Science

Java/JavaFX: Write up some simple sample code to demonstrate indirect recursion.  You can just use print statements...

Java/JavaFX: Write up some simple sample code to demonstrate indirect recursion.  You can just use print statements to demonstrate how they call one another.  

Submit your working .java file here for credit.

Solutions

Expert Solution

class Test { // class to call recurring functions

        public void recur1(int n) {
                if (n < 0) {
                        return; // base condition
                } else {
                        System.out.println("Calling recur2");
                        recur2(--n); // calling indirect recursion
                }
        }

        public void recur2(int n) {
                if (n < 0) {
                        return; // base condition
                } else {
                        System.out.println("Calling recur1");
                        recur1(--n); // calling indirect recursion
                }
        }

        public static void main(String[] args) {
                Test t = new Test(); // creating an instance of Test class
                t.recur1(5);
        }

}

Related Solutions

Write a simple Java code to make a Binary Tree for the following tree: Don’t use...
Write a simple Java code to make a Binary Tree for the following tree: Don’t use serializable interface implantation /** Class to encapsulate a tree node. */ protected static class Node implements Serializable {
write a java program of mickey mouse it can be simple with just ears face eyes...
write a java program of mickey mouse it can be simple with just ears face eyes and mouth
Can you fix to me this code plz I just want to print this method as...
Can you fix to me this code plz I just want to print this method as the reverse. the problem is not printing reverse. public void printBackward() {               Node curr = head;        Node prev = null;        Node next = null;               System.out.print("\nthe backward of the linkedlist is: ");               while(curr != null) {            next = curr.next;            curr.next = prev;   ...
write the program in java. Demonstrate that you understand how to use create a class and...
write the program in java. Demonstrate that you understand how to use create a class and test it using JUnit Let’s create a new Project HoursWorked Under your src folder, create package edu.cincinnatistate.pay Now, create a new class HoursWorked in package edu.cincinnatistate.pay This class needs to do the following: Have a constructor that receives intHours which will be stored in totalHrs Have a method addHours to add hours to totalHrs Have a method subHours to subtract hours from totalHrs Have...
Write the program in Java. Demonstrate that you know how to define variables, create conditional statements,...
Write the program in Java. Demonstrate that you know how to define variables, create conditional statements, write a loop, use arrays, obtain input from the user, display output, test and create a JavaDoc. Create project PaystubTest2 that is a Paystub calculator with program Paystub##.java (where ## is your initials) based on user input. (10 points) You must use the ReadStringFromUser and ReadFloatFromUser methods in the program to obtain user input. (20 points) This program will calculate the Gross Earnings, FICA...
In Java, you can iterate an ArrayList in different ways. Write the following methods to print...
In Java, you can iterate an ArrayList in different ways. Write the following methods to print Integers in an ArrayList iterating in different ways: 1. // Using basic while / for loop void printArrayListBasicLoop(ArrayList<Integer> al); 2. // Using enhanced for loop (:) void printArrayListEnhancedLoop(ArrayList<Integer> al); 3. // Using basic for loop with iterator void printArrayListForLoopListIterator(ArrayList<Integer> al); 4. // Using basic while loop with iterator void printArrayListWhileLoopListIterator(ArrayList<Integer> al);
To get some practice with recursion. You can do all this in one driver program. Write...
To get some practice with recursion. You can do all this in one driver program. Write a recursive method to compute the result of the Fibonacci sequence: Fibonacci(N) = Fibonacci(N -1) + Fibonacci(N-2) N == 0 is 0 N == 1 is 1 Testing: Display the result for Fibonacci(N) and the number of function calls for N = 2, 5 and 10.
Can you write a small program in c++ demonstrate the use of pointer (*) & (&)....
Can you write a small program in c++ demonstrate the use of pointer (*) & (&). Can you also explain the pointer system and how to use them. Thank you.
PLEASE CODE IN JAVA In this assignment you will write a program in that can figure...
PLEASE CODE IN JAVA In this assignment you will write a program in that can figure out a number chosen by a human user. The human user will think of a number between 1 and 100. The program will make guesses and the user will tell the program to guess higher or lower.                                                                   Requirements The purpose of the assignment is to practice writing functions. Although it would be possible to write the entire program in the main function, your...
To come up with a problem definition, write up some sample questions you would ask the...
To come up with a problem definition, write up some sample questions you would ask the president of Java Airlines to better help what they would like their software to do. Be Creative in your questions! Write up a mock Problem Definition Statement to summarize what you think the Java Airline software should be. Attention to detail will earn full marks on this assignment.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT