3个回答
展开全部
public class RunThread implements Runnable{
String name;
Thread runner;
static boolean bool=true;
public RunThread(String threadName) {
name=threadName;
}
public void onStart()
{
runner = new Thread(this);
runner.setName(name);
runner.start();
}
public void run() {
String name=Thread.currentThread().getName();
System.out.println(name + " 线程运行开始!");
int index=0;
if(name.equals("小写字母"))
index='a';
else if(name.equals("大写字母"))
index='A';
while(!bool);
bool=false;
for(int i=index;i<26+index;i++)
System.out.print((char)i+" ");
System.out.println();
bool=true;
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(name + " 线程运行结束!");
}
public static void main(String[] args) {
RunThread a=new RunThread("小写字母");
RunThread b=new RunThread("大写字母");
a.onStart();
b.onStart();
//System.out.println(" 线程运行开始!");
}
String name;
Thread runner;
static boolean bool=true;
public RunThread(String threadName) {
name=threadName;
}
public void onStart()
{
runner = new Thread(this);
runner.setName(name);
runner.start();
}
public void run() {
String name=Thread.currentThread().getName();
System.out.println(name + " 线程运行开始!");
int index=0;
if(name.equals("小写字母"))
index='a';
else if(name.equals("大写字母"))
index='A';
while(!bool);
bool=false;
for(int i=index;i<26+index;i++)
System.out.print((char)i+" ");
System.out.println();
bool=true;
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(name + " 线程运行结束!");
}
public static void main(String[] args) {
RunThread a=new RunThread("小写字母");
RunThread b=new RunThread("大写字母");
a.onStart();
b.onStart();
//System.out.println(" 线程运行开始!");
}
展开全部
public class DoubleThread {
public static void main(String[] args) {
Thread t1 = new Thread() {
@Override
public void run() {
for (char i = 'a'; i <= 'z'; i++) {
System.out.println(i);
}
}
};
Thread t2 = new Thread() {
@Override
public void run() {
for (char i = 'A'; i <= 'Z'; i++) {
System.out.println(i);
}
}
};
t1.start();
t2.start();
}
}
public static void main(String[] args) {
Thread t1 = new Thread() {
@Override
public void run() {
for (char i = 'a'; i <= 'z'; i++) {
System.out.println(i);
}
}
};
Thread t2 = new Thread() {
@Override
public void run() {
for (char i = 'A'; i <= 'Z'; i++) {
System.out.println(i);
}
}
};
t1.start();
t2.start();
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
顶一楼的兄弟!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询