wo317458719 于 2016.03.22 23:10 提问

``````public class Banck {
private Double[] accounts;
public Banck(int n,Double inintPrice) {
accounts= new Double[n];
for(int i=0;i<n;i++){
accounts[i]=inintPrice;
}
}

public  void transfer(Integer from,Integer to,Double mouny) throws InterruptedException{
synchronized(accounts){
while(accounts[from]<mouny){
return;
}
accounts[from]-=mouny;
System.out.printf(" 金额 %10.2f 从账户  %d 到  %d",mouny,from,to);
accounts[to]+=mouny;
System.out.printf(" 总金额 %10.2f",getTotal());
System.out.println();
}
}

public  Double getTotal() throws InterruptedException{
double total=0d;
synchronized(accounts){
for( int i=0;i<accounts.length;i++){
total+=accounts[i];
}
}
}
public int size(){
return accounts.length;
}
public Double[] getAccounts() {
return accounts;
}

public void setAccounts(Double[] accounts) {
this.accounts = accounts;
}

}
``````

#############################
public class TransferRunnable implements Runnable{
private Banck banck;
private Double amount;
private int fromBank;
public TransferRunnable(Banck bank,int from , Double amount){
this.banck=bank;
this.fromBank=from;
this.amount=amount;
}
@Override
public void run() {
synchronized(this){
while(true){
int toBanck=(int)(banck.size()*Math.random());
Double mouny=amount*Math.random();
try {
banck.transfer(fromBank, toBanck, mouny);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
System.out.println("---"+banck.getTotal());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public Banck getBanck() {
return banck;
}
public void setBanck(Banck banck) {
this.banck = banck;
}
public int getFromBank() {
return fromBank;
}
public void setFromBank(int fromBank) {
this.fromBank = fromBank;
}
public Double getAmount() {
return amount;
}
public void setAmount(Double amount) {
this.amount = amount;
}

``````}
``````

############################################

``````public static void main(String[] args) {
Banck b=new Banck(10,100d);
for(int i=0;i<b.size();i++){
TransferRunnable tr=new TransferRunnable(b,i,100d);
t.start();
}
}

}
``````

---1000.0

---1000.0

---1000.0

---1000.0

---1000.0000000000001

---1000.0
---1000.0

---1000.0

---999.9999999999999

---999.9999999999999

---999.9999999999999
---999.9999999999999

2个回答

devmiao      2016.03.22 23:56

wojiushiwo945you      2016.03.23 11:40

`````` @Override
public void run() {
synchronized (banck) {
}
}
``````

Tomcat服务器启动失败其中原因之一

c语言

想问一下.... 父窗口是以  USERCONTROL 组合而成的, 在子窗口中写入一些字  点按钮之后 怎样把那些字传给父窗口中USERCONTROL 中的TEXTBOX 里    opener.document.all.txt.value = "ajsdklfhwiuefiuh" 这个只能传给父窗口中的 TEXTBOX 不能传给 USERCONTROL中的TEXTBOX.......

写了个老鼠走迷宫的代码，结果准备打印出走之前的地图和走之后的地图，不知道为啥，只输出了前一个，而没有后一个。     好心的人帮我看看是怎么回事，不胜感激。源代码：#include#define EAST MAZE[x][y+1]   #define WEST MAZE[x][y+1] #define SOUTH MAZE[x][y+1] #define NORTH MAZE

// 编写程序：通过键盘输入若干学生信息（学号，姓名，年龄，考分），保存在文件stu.dat中 #include #include void main() {     int i,j;     typedef struct stu     {         int num;         char name[32];         int age;         fl