[backcolor=rgb(244, 244, 244) !important]public class Demo { public static void main(String[] args) { [backcolor=rgb(244, 244, 244) !important] Thread t = new Thread() { public void run() { [backcolor=rgb(244, 244, 244) !important] for (int i = 1; i <= 5; i++) { System.out.print(i + " "); [backcolor=rgb(244, 244, 244) !important] } } [backcolor=rgb(244, 244, 244) !important] }; t.start(); [backcolor=rgb(244, 244, 244) !important] } } |
运行结果:1 2 3 4 5
[backcolor=rgb(244, 244, 244) !important]1 2 [backcolor=rgb(244, 244, 244) !important]3 4 [backcolor=rgb(244, 244, 244) !important]5 6 [backcolor=rgb(244, 244, 244) !important]7 8 [backcolor=rgb(244, 244, 244) !important]9 10 [backcolor=rgb(244, 244, 244) !important]11 12 [backcolor=rgb(244, 244, 244) !important]13 | [backcolor=rgb(244, 244, 244) !important]public class Demo { public static void main(String[] args) { [backcolor=rgb(244, 244, 244) !important] Runnable r = new Runnable() { public void run() { [backcolor=rgb(244, 244, 244) !important] for (int i = 1; i <= 5; i++) { System.out.print(i + " "); [backcolor=rgb(244, 244, 244) !important] } } [backcolor=rgb(244, 244, 244) !important] }; Thread t = new Thread(r); [backcolor=rgb(244, 244, 244) !important] t.start(); } [backcolor=rgb(244, 244, 244) !important]} |
=
=
=
=
=
| 欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |