英文:
Why does my program terminate without giving any output in java?
问题
以下是您要翻译的内容:
我正在尝试在Java中编译这段代码,但它在不提供任何输出或错误的情况下终止。
public class findEvenQueue {
public int mysteryMethod(int n) {
if (n <= 2) {
return 2;
} else {
return mysteryMethod(n - 1) + mysteryMethod(n - 2);
}
}
public static void main(String[] args) {
findEvenQueue a = new findEvenQueue();
a.mysteryMethod(4);
}
}
英文:
I am trying to compile this code in Java but it terminates without providing any output or errors.
public class findEvenQueue {
public int mysteryMethod(int n) {
if (n <= 2) {
return 2;
} else {
return mysteryMethod(n - 1) + mysteryMethod(n - 2);
}
}
public static void main(String[] args) {
findEvenQueue a = new findEvenQueue();
a.mysteryMethod(4);
}
}
答案1
得分: 0
你的代码没有在控制台上打印任何内容。将你的代码更改如下:
public class findEvenQueue {
public int mysteryMethod(int n) {
if (n <= 2) {
return 2;
} else {
return mysteryMethod(n - 1) + mysteryMethod(n - 2);
}
}
public static void main(String[] args) {
findEvenQueue a = new findEvenQueue();
System.out.println(a.mysteryMethod(4));
}
}
英文:
Your code is not printing anything on the console. Change your code as below
public class findEvenQueue {
public int mysteryMethod(int n) {
if (n <= 2) {
return 2;
} else {
return mysteryMethod(n - 1) + mysteryMethod(n - 2);
}
}
public static void main(String[] args) {
findEvenQueue a = new findEvenQueue();
System.out.println(a.mysteryMethod(4));
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论