完成用一个线程负责打印1-26的数字,另一个线程负责打印A-Z 要求打印的结果为:1 2 A 3 4 B 5 6 C 7 8 D 9 10 1 12 ... 521 E F G H I J K ... X Y Z
解决方案 »
- Java 作业 求解答 谢谢
- CAS 单点登录该怎么玩啊
- (高手快来帮帮忙啊)Java下载文件
- struts2 标签 form 的action问题
- [200分???关于jpetstore的aop配置]老是提示:not eligible for auto-proxying
- 出现org.springframework.transaction.UnexpectedRollbackException的原因是什么?
- Cannot create mapping for java.util.List, unspecified component type for interfa
- tomcat5.0连接池问题,得到的连接总是为null,郁闷,请高人指点
- 在WIN2000中,数据库用SQLServer 2000,怎样配置weblogic6.1sp1?急!!!!!!!!!!
- springboot向数据库添加数据时空指针
- [SOS]如何隐藏掉hibernate日志中的密码
- 关于Hibernate查询出数据不同步问题
public static void main(String[] args) {
new Thread(new Runnable() {
public void run() {
synchronized (ThreadTest.class) {
int m = 1;
while (m <= 26) {
if (bShouldMain) {
try {
ThreadTest.class.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.print(m++);
System.out.print(m++);
bShouldMain = true;;
ThreadTest.class.notify(); }
} }
}).start();
synchronized (ThreadTest.class) {
char k = 'A';
while (k <= 'Z') {
if (!bShouldMain) {
try {
ThreadTest.class.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.print(k++);
System.out.print(k++);
bShouldMain = false;
ThreadTest.class.notify();
}
} }}
package com.ambow.day10;public class TextThread {
public static void main(String[] args) {
TreadTake th = new TreadTake();
ThreadTake2 t = new ThreadTake2(th);
th.start();
t.start();
}
}
class TreadTake extends Thread{
public void run(){
for(int i=1;i<=26;i++){
System.out.println(2*i-1);
System.out.println(2*i);
try {
Thread.currentThread().sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}class ThreadTake2 extends Thread{
private Thread t;
public ThreadTake2(Thread t){
this.t=t;
}
public void run(){
for(char i='A';i<='Z';i++){
System.out.println(i);
if(i=='D'){
try {
t.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
Thread.currentThread().sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
在输出结果中前段必须是1 2 A 3 4 B 5 6 C 7 8 D这样的输出 后面的就是输出余下的数字后再输出字母(这个jion()方法一实现 我现在想做的就是怎么控制前面一段按这样de "1 2 A 3 4 B 5 6 C 7 8 D"输出