Home

About

Advanced Search

Browse by Discipline

Scientific Societies

E-print Alerts

Add E-prints

E-print Network
FAQHELPSITE MAPCONTACT US


  Advanced Search  

 
Recursion Practice: 1. Write a recursive method that has one parameter which is an int value called x. The method
 

Summary: Recursion Practice:
1. Write a recursive method that has one parameter which is an int value called x. The method
prints x asterisks, followed by x exclamation points. Do NOT use any loops. Do NOT use any
variables other than x.
2. Implement the following method. Do not use any local variables or loops.
public static void pattern(int n)
// Precondition: n > 0;
// Postcondition: The output consists of lines of integers. The first line
// is the number n. The next line is the number 2n. The next line is
// the number 4n, and so on until you reach a number that is larger than
// 4242. This list of numbers is then repeated backward until you get back
// to n.
/* Example output with n = 840:
840
1680
3360
6720
6720
3360
1680

  

Source: Allan, Vicki H. - Department of Computer Science, Utah State University

 

Collections: Computer Technologies and Information Sciences