📄 chapter21n6.java
字号:
/** * * demonstration of threads version III * * Written by: Roger Garside * * First Written: 6/Feb/97 * Last Rewritten: 6/Feb/97 * */class ProcessString2 implements Runnable { private String originalString ; public ProcessString2(String string) { originalString = string ; Thread thisThread = new Thread(this) ; thisThread.start() ; } // end of constructor method public void run() { int offset = 0 ; while (true) { String s = originalString.substring(0, offset) + Character.toUpperCase(originalString.charAt(offset)) + originalString.substring(offset + 1) ; System.out.println("**" + s + "**") ; offset++ ; if (offset == originalString.length()) offset = 0 ; try { Thread.sleep(1000) ; } catch (InterruptedException e) { } } } // end of method run } // end of class ProcessString2public class Chapter21n6 { public static void main(String[] args) { ProcessString2 p1 = new ProcessString2("lancaster") ; ProcessString2 p2 = new ProcessString2("preston") ; ProcessString2 p3 = new ProcessString2("kendal") ; while (true) { System.out.println("Hello again") ; try { Thread.sleep(5000) ; } catch (InterruptedException e) { } } } // end of method main } // end of class Chapter21n6
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -