日期:2014-05-20 浏览次数:20747 次
public static void main(String args[]) { printNum(1); } public static void printNum(int n) { if(n == 100) { System.out.println(n); } else { System.out.println(n); printNum(n + 1); } }
------解决方案--------------------
public class Test1 { public static synchronized void main(String[] a) { int i =0; getNumber(i); } static void getNumber(int i) { i++; System.out.println(i); if (i < 100) getNumber(i); } }
------解决方案--------------------
public class Test { public void Test_1(int a) { if(a <= 100) { System.out.println(a); Test(++a); } } public static void main(String[] args) { Test test = new Test(); test.Test_1(1); } }
------解决方案--------------------
code=Java]
public void printNum(int n)
{
if(n==1)
System.out.println(n);
else
{
printNum(n-1);
System.out.println(n);
}
}[
[/code]
------解决方案--------------------
用递归
printNum(100); public void printNum(int i){ System.out.println(i); if(i==1){ return; }else{ printNum(--i); } }
------解决方案--------------------
import java.util.Date; import java.util.Timer; import java.util.TimerTask; public class Test01 { public static void main(String[] args) { final int len = 100; final Timer timer = new Timer(); timer.schedule(new TimerTask() { private int i = 1; public void run() { System.out.println(i++); if (i > len) { this.cancel(); timer.cancel(); } } }, new Date(), 1); } }
------解决方案--------------------
整理了一下2个方法
import java.util.Timer; import java.util.TimerTask; public class T { public static void main(String[] arge) { show(100); show2(100); } public static void show(int num) { if (num > 1) { show(num - 1); } System.out.println(num); } public static void show2(final int num) { final Timer timer = new Timer(); timer.schedule(new TimerTask() { private int i = 0; @Override public void run() { if (i <= num) { System.out.println(i++); } else { timer.cancel(); } } }, 0, 1); } }
------解决方案--------------------