當前位置:編程學習大全網 - 編程軟體 - 解壹題簡單的編程題

解壹題簡單的編程題

import com.sun.java_cup.internal.internal_error;

public static class Prm

{

public int ATM_total = 200;

}

public class ATM extends Thread

{

public static void main(String args[])

{

AThread aThread = new AThread();

aThread.start();

BThread bThread = new BThread();

bThread.start();

}

}

public class AThread extends Thread

{

public void run()

{

int amt = Prm.ATM_total;

try

{

this.sleep(2000);

}

catch (InterruptedException e)

{

e.printStackTrace();

}

amt += 100;

Prm.ATM_total = amt;

try

{

this.sleep(2000);

}

catch (InterruptedException e)

{

e.printStackTrace();

}

}

}

public class BThread extends Thread

{

public void run()

{

int amt = Prm.ATM_total;

try

{

this.sleep(2000);

}

catch (InterruptedException e)

{

e.printStackTrace();

}

if(amt > 50)

{

amt -= 50;

}

else

{

throw new Exception();

}

Prm.ATM_total = amt;

try

{

this.sleep(2000);

}

catch (InterruptedException e)

{

e.printStackTrace();

}

}

}

  • 上一篇:幫幫我,開幹洗店賺錢?幹洗店累嗎?真的嗎?
  • 下一篇:從壹些數中選出若幹個求和,使得和與另壹個數的差值最小(c語言編程)
  • copyright 2024編程學習大全網