English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Obtain the final answer using recursive boxes: problem 1
int mist (int n){
if (n == 1){
return 3;
}else{
return 3 * mist(n-1);
}
}
What values does mist (5) return?


Obtain the final answer using recursive boxes: problem 2
void misty(int n){
if (n > 4){
misty (n % 4);
}
System.out.print(n / 4 + ""):
}
What sequence of numbers will the call to misty (38) yield?

2007-02-21 13:42:02 · 2 answers · asked by jumba 1 in Computers & Internet Programming & Design

2 answers

Here is my Test.java class:

public class Test {

public Test(){
}


public static void main(String[] args) {
Test a = new Test();
int answer = a.mist(5);
System.out.println("answer = " + answer);
a.misty(38);

}

int mist (int n){
if (n == 1){
return 3;
}else{
return 3 * mist(n-1);
}
}

void misty(int n){
if (n > 4){
misty (n % 4);
}
System.out.print(n / 4 + "");
}
}


The output is:

answer = 243
09

2007-02-21 13:51:07 · answer #1 · answered by SPB 6 · 0 0

You might want to double-check, in case if i have missed anything, but I think the answers are:
1) 243
2) 0 9

2007-02-21 22:17:37 · answer #2 · answered by A.Samad Shaikh 2 · 0 0

fedest.com, questions and answers