Does anyone know why I am NOT getting output, my output is supposed to be in thi
ID: 3649997 • Letter: D
Question
Does anyone know why I am NOT getting output, my output is supposed to be in this format:
1,1
1,2
1,3
1,4,
1,5
2,1
2,2
2,3
2,3
2,4
2,5
3,1
3,2
3,3
3,4
3,5
Here is my code
public class testNum {
public static int Ack(int m, int n) {
if (m == 0) {
return 2 * n;
} else if (m >= 1) {
if (n == 0) {
return 0;
} else if (n == 1) {
return 2;
} else {
return Ack(m - 1, Ack(m, n - 1));
}
}
return n; // Not sure what to return here, Eclipse suggested this.
}
public static void main(String args[]) {
System.out.println(Ack(3, 4));
}
}
Explanation / Answer
please rate - thanks
I fixed your method
the function only returns 1 value, so it appears you need nexted loop to call it
Please message me before rating if any problem
public class testNum {
public static int Ack(int m, int n) {
if(m==0)
return (n+1);
else
if(n==0)
return (Ack(m-1,1));
else
return(Ack(m-1,Ack(m,n-1)));
}
public static void main(String args[]) {
for(int i=1;i<4;i++)
for(int j=1;j<6;j++)
System.out.println(i+","+j+"="+Ack(i,j));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.