`

多线程

 
阅读更多
/**
 * 用多线程的知识,写一个应用程序,该应用程序要求能交错打印数字和字母,打印的效果如下
 * A1B2C3D4E5F6
 * @author 够潮
 *
 */
public class Demo5 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		Num num = new Num();
		Character ch = new Character();
		Thread threadNum = new Thread(num);
		Thread threadCh = new Thread(ch);
		/**
		 * 启动线程
		 */
		threadNum.start();
		threadCh.start();

	}

}
/**
 * 打印数字
 * @author 
 *
 */
class Num implements Runnable{

	public void run() {
		// TODO Auto-generated method stub
		
		for(int i = 0 ; i < 100;i++){
			System.out.print(i+" ");
		}
	}
	
	
}
/**
 * 打印字符
 * @author Administrator
 *
 */
class Character implements Runnable{

	public void run() {
		// TODO Auto-generated method stub
		
		for(char i = 'A' ; i < 'Z';i++){
			System.out.print(i+" ");
		}
	}
	
	
}

 

0
4
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics