<分区>
Possible Duplicate:
Display numbers from 1 to 100 without loops or conditions
面试问题:
在 java 中无任何循环地打印 1 到 10。
标签 java
<分区>
Possible Duplicate:
Display numbers from 1 to 100 without loops or conditions
面试问题:
在 java 中无任何循环地打印 1 到 10。
最佳答案
简单方法:System.out.println
值:
System.out.println(1);
System.out.println(2);
System.out.println(3);
System.out.println(4);
System.out.println(5);
System.out.println(6);
System.out.println(7);
System.out.println(8);
System.out.println(9);
System.out.println(10);
复杂的方式:使用递归
public void recursiveMe(int n) {
if(n <= 10) {// 10 is the max limit
System.out.println(n);//print n
recursiveMe(n+1);//call recursiveMe with n=n+1
}
}
recursiveMe(1); // call the function with 1.
关于java - 在 java 中打印 1 到 10 没有任何循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9408210/