我想交替运行两个线程来写下字母表。不知道我在代码中写错了什么,但是 IDE 无法解析 .start()-Method。搜索了很多,但找不到我的问题的答案。我感谢每一个想法。
public class ABCThread_2 implements Runnable
{
private boolean issmall;
private boolean istall;
public ABCThread_2(boolean istall, boolean issmall)
{
this.istall = istall;
this.issmall = issmall;
}
public void run()
{
if(issmall)
{
for (char c = 'a'; c <= 'z'; c++)
{
try
{
Thread.sleep(250);
}
catch (InterruptedException e)
{
}
System.out.print(c);
}
}
else if(istall)
{
for (char c = 'A'; c <= 'Z'; c++)
{
try
{
Thread.sleep(250);
}
catch(InterruptedException e)
{
}
System.out.print(c);
}
}
}
public static void main(String [] args)
{
ABCThread_2 th1 = new ABCThread_2(false, true);
ABCThread_2 th2 = new ABCThread_2(true, false);
th1.start();
th2.start();
}
}
慕森卡
慕雪6442864
相关分类