In: Computer Science
Write a method called recursiveDownAndUp() that takes one non-negative integer parameter, recursively starts at one thousand and prints all the integers from one thousand to the parameter (that is, prints 1000, 999, etc. all the way down to the parameter), then recursively starts at the integer parameter and prints all the integers from the parameter up to one thousand (that is, prints the parameter, the parameter + 1, the parameter + 2, etc. all the way up to 1000).
CODE
public class Main
{
public static void recursiveDownAndUp(int k) {
recursiveDown(1000, k);
System.out.println();
System.out.println();
recursiveUp(k, 1000);
}
public static void recursiveDown(int n, int k) {
if (n < k) {
return;
}
System.out.print(n + " ");
recursiveDown(n-1, k);
}
public static void recursiveUp(int k, int n) {
if (n < k) {
return;
}
System.out.print(k + " ");
recursiveUp(k+1, n);
}
public static void main(String args[])
{
recursiveDownAndUp(900);
}
}