public class English { private class Upper implements Runnable { public void run() { upper(); } } private class Lower implements Runnable { public void run() { lower(); } } private void upper() { for (char c='a'; c<='z'; c++) { System.out.print(c); } System.out.println(); } private void lower() { for (char c='A'; c<='Z'; c++) { if (c=='A') { Thread.yield(); } try { Thread.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } System.out.print(c); } System.out.println(); } public static void main(String[] args) throws InterruptedException { English test = new English(); Upper upper = test.new Upper(); Lower lower = test.new Lower(); Thread t1=new Thread(upper); t1.start(); Thread t2=new Thread(lower); t2.start(); } }
双线程输出26个大小写字母
最新推荐文章于 2022-05-21 11:08:20 发布