第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用Java編寫一個簡單的存款

用Java編寫一個簡單的存款

慕容708150 2019-03-01 11:15:12
package desposit.money; public class DespositMoney { public static void main(String[] args) { Customer c1 = new Customer("第一個顧客",3); Customer c2 = new Customer("第二個顧客",10); Customer c3 = new Customer("第三個顧客",5); c1.start(); c2.start(); c3.start(); } } class Customer extends Thread{ private int time; String s; public Customer(String s,int time){ this.s = s; this.time = time; } public void run(){ while(true) { synchronized(this){ if(time>0) { Total.sum+=100; System.out.println(s+"存款100元,銀行總共有存款"+Total.sum+"元"); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } time --; } if(time ==0) { System.out.println(s+"存款結(jié)束"); break; } } } } } class Total { public static int sum = 0; } 運行結(jié)果不是從100,200,......,到1800,中間總有重復(fù)的數(shù)字,但最后的結(jié)果總和是1800
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 616 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號