Groups
Groups
Sign in
Groups
Groups
EnJoyJava
Conversations
About
Send feedback
Help
for - 程式設計【多執行緒同步處理】
1 view
Skip to first unread message
q738...@yahoo.com.tw
unread,
Dec 29, 2010, 2:38:48 AM
12/29/10
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to EnJoyJava
class bank extends Thread {
private static int sum = 0;
public bank (String name) {
this.setName(name);
}
public void run () {
for (int i=1; i <= 5; i++)
try {
Thread.sleep(1000);
sum += 50;
System.out.printf("「%s」累加匯款「%d」\n",getName(),sum);
} catch (Exception e) {
System.out.println("程式發生錯誤");
}
}
}
public class example {
public static void main (String[] ymc) throws Exception{
bank bank1 = new bank("王小明");
bank bank2 = new bank("金大蔥");
bank1.start();
bank2.start();
}
}
Reply all
Reply to author
Forward
0 new messages