Java Recursion Example

Feb 3rd, 2012
Studypool Tutor
Price: $5 USD

Tutor description

public class Recursion6 { /** * Start of class. Must enter a commandline argument and it Must be an integer */ public static void main(String [] arguments)

Word Count: 380
Showing Page: 1/6
import java.util.*;public class Recursion6{ /** * Start of class. Must enter a commandline argument and it Must be an integer */ public static void main(String [] arguments) { if(arguments.length == 0) { System.out.println("ERROR: Enter at least one commandline argument."); } else { /** * gets the commandline input and converts to an integer * plugs into methods for later use */ try { int x; x = Integer.parseInt(arguments[0]); Recursion6.reverse(x); Recursion6.forward(0, x); Integer result = Recursion6.sum(x);System.out.println(x + "! = " + result); Recursion6.twoPower(0, x); System.out.println("\nMethod4 - SUM is " + method4(x)); } //catch statement for string inputed into commandline catch (NumberFormatException e) { System.out.println("you must enter an integer"); } } } //method for printing astericks. //keeps printing until the amount entered into the commandline public static String astericks(String xk) { //convert x to a integer int k = Integer.parseInt(xk); //K is always used for recursion sequence. //X is for the amount entered if(k == 0)return xk;if(k > 0) {k = k - 1;astericks("*" + "*");}return xk; } //method for printing in reverse order //keeps print

Review from student

Studypool Student
" Excellent work as always thanks so much "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1819 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors