Question
java
Fill in the blanks to complete the following recursive program. It shou print a pattern like the one below. using System.out.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
Answer:
public static void gt(int count, boolean flag, int n){
    System.out.print(nspaces(count-1));
    System.out.println("*");
    if(flag && count<=n){
        if(count == n){
            gt(count-1, !flag, n);
        }
        else {
            gt(count + 1, flag, n);
        }
    }
    else{
        if(count==1){
            return;
        }
        gt(count-1, flag, n);
    }
}

Function call :

gt(1,true,3);
Add a comment
Know the answer?
Add Answer to:
java Fill in the blanks to complete the following recursive program. It shou print a pattern...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • S1I Summer 09 Page 7 Practice Final Exam (30 points) Fill in the blanks to complete...

    S1I Summer 09 Page 7 Practice Final Exam (30 points) Fill in the blanks to complete the following recursive program It should print a pattern like the one below, using System.out.printin. The argument, lines, says how many lines long the pattern should be. Assume you have a method String nspaces(n) which returns a string containing n spaces. CYou should not write nspaces.) Here is the pattern when lines is 4. The first line VI. name has one space before the...

  • Fill in the blanks only where it is needed and complete the following program for computing...

    Fill in the blanks only where it is needed and complete the following program for computing a Fibonacci number. JAVA   public static long fib(long index) {     if (index == 0) _____________________________       return 0; _____________________________     else if (index == 1) _____________________________       return 1; _____________________________     else  _____________________________       return _____________________________

  • Complete java program below. Complete non-recursive version nthFibonacciWithLoop() method. Complete recursive version nthFibonacciWithRecursion() method. public class...

    Complete java program below. Complete non-recursive version nthFibonacciWithLoop() method. Complete recursive version nthFibonacciWithRecursion() method. public class Fibonacci { // Fib(N): N N = 0 or N = 1 // Fib(N-1) + Fib(N-2) N > 1 // For example, // Fib(0) = 0 // Fib(1) = 1 // Fib(2) = Fib(1) + Fib(0) = 1 + 0 = 1 // Fib(3) = Fib(2) + Fib(1) = Fib(2) + 1 = (Fib(1) + Fib(0)) + 1 = 1 + 0 + 1...

  • Prelab Exercises Your task is to write a Java program that will print out the following...

    Prelab Exercises Your task is to write a Java program that will print out the following message (including the row of equal marks): Computer Science, Yes!!!! ========================= An outline of the program is below. Complete it as follows: a. In the documentation at the top, fill in the name of the file the program would be saved in and a brief description of what the program does. b. Add the code for the main method to do the printing. //...

  • (20 pts) Fill in the missing code: This recursive method returns “even” if the length of...

    (20 pts) Fill in the missing code: This recursive method returns “even” if the length of a give String is even, and “odd” if the length of the String is odd. public static String foo(String s) { if (s.length() ==0)    return “even”; else if (s.length() = = 1)    return “odd”; else     //your code goes here } (40 pts) You coded the following in the file Test.java : System.out.println( foo(5)); //more code here public static int foo(int n)...

  • Modify the following given Java program. You are expected to modify the supplied Exercise1.java to print...

    Modify the following given Java program. You are expected to modify the supplied Exercise1.java to print just the last lines of each paragraph in HTML format. Copy and paste the Sample input on the console then print the Expected output. import java.util.Scanner; public class Exercise1 { /** A simple static string for HTML & table header. */ private static final String HTMLHeader = "<!DOCTYPE html>\n" + " <html>\n" + " <head>\n" + " <title>CSE: Exercise 1</title>\n" + " </head>\n" +...

  • Question 2: Levenshtein Take the recursive Java program Levenshtein.java and convert it to the equivalent C...

    Question 2: Levenshtein Take the recursive Java program Levenshtein.java and convert it to the equivalent C program. Tip: You have explicit permission to copy/paste the main method for this question, replacing instances of System.out.println with printf, where appropriate. Notes You can get the assert function from assert.h. Try running the Java program on the CS macOS machines. You can compile and run the program following the instructions provided in assignment 0. Assertions are disabled by default. You can enable assertions...

  • You will implement and test several short recursive methods below. With the proper use of recursi...

    this can be done in one class or two separate classes,in java thanks! You will implement and test several short recursive methods below. With the proper use of recursion, none of these methods should require more than a dozen lines of code. Test all these in the same class. Keep adding methods and testing until all are working 5. A Fractal Pattern Examine this pattern of stars and blanks, and write a recursive method that can generate patterns such as...

  • Complete the following Java program by writing the missing methods. public class 02 { public static...

    Complete the following Java program by writing the missing methods. public class 02 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter a number: int n = scan.nextInt(); if (isOdd (n)) { //Print n to 1 System.out.println("Print all numbers from "+n+" to 1"); printNumToOne (n); } else { System.out.println(n + " is //End of main()

  • Looking for some simple descriptive pseudocode for this short Java program (example italicized in bold directly...

    Looking for some simple descriptive pseudocode for this short Java program (example italicized in bold directly below): //Create public class count public class Count {     public static void main(String args[])     {         int n = getInt("Please enter an integer value greater than or equal to 0");                System.out.println("Should count down to 1");         countDown(n);                System.out.println();         System.out.println("Should count up from 1");         countUp(n);     }            private static void countUp(int n)     {...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT