题目:1、用两种方式实现两个线程,一个线程负责打印1-2600,另一个线程打印A-Z,反复打印100遍
1 package com.zhuoyue.ch13; 2 3 /* 4 * 继承Thread实现 5 */ 6 7 public class MyThread1 extends Thread{ 8 public void run(){ 9 for(int i=1;i<=2600;i++){ 10 System.out.println(i); 11 } 12 } 13 14 }
1 package com.zhuoyue.ch13; 2 /* 3 * 继承接口实现 4 */ 5 public class MyThread2 implements Runnable{ 6 7 @Override 8 public void run() { 9 for(int i='A';i<='Z';i++){ 10 System.out.println((char)i); 11 12 } 13 } 14 15 }
1 package com.zhuoyue.ch13; 2 3 public class TestThread { 4 5 public static void main(String[] args) { 6 7 Thread t1 = new MyThread1(); 8 t1.start(); 9 10 Runnable r1 = new MyThread2(); 11 Thread t2 = new Thread(r1); 12 t2.start(); 13 } 14 15 }