Guest User

Untitled

a guest
Aug 18th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. public class Main {
  2.  
  3. static int cap = 100;
  4. static int time = 0;
  5.  
  6. static Thread plus;
  7. public static void main(String[] args) throws InterruptedException {
  8.  
  9. Thread drink = new Thread(new Runnable(){
  10. @Override
  11. public void run() {
  12. while (cap > 0) {
  13. try {
  14. Thread.sleep(3000);
  15. } catch (InterruptedException e) {}
  16. cap -= 10;
  17. System.out.println(cap);
  18. time += 3;
  19. }
  20. Thread.currentThread().interrupt();
  21. plus.interrupt();
  22. System.out.println(time);
  23. }
  24. });
  25.  
  26. plus = new Thread(new Runnable(){
  27. @Override
  28. public void run() {
  29. while (cap > 0) {
  30. try {
  31. Thread.sleep(6000);
  32. } catch (InterruptedException e) {}
  33. cap += 10;
  34. System.out.println(cap);
  35. time += 6;
  36. }
  37. Thread.currentThread().stop();
  38. }
  39. });
  40.  
  41. drink.start();
  42. plus.start();
  43. }
  44. }
  45.  
  46. public class Main {
  47.  
  48. static int cap = 100;
  49. static int time = 0;
  50.  
  51. static Thread plus;
  52.  
  53. public static void main(String[] args) {
  54.  
  55. Thread drink = new Thread(new Runnable() {
  56. @Override
  57. public void run() {
  58. while (cap > 0) {
  59. try {
  60. Thread.sleep(3000);
  61. } catch (InterruptedException ignored) {
  62. }
  63. cap -= 10;
  64. System.out.println(cap);
  65. time += 3;
  66. }
  67. plus.interrupt();
  68. System.out.println(time);
  69. }
  70. });
  71.  
  72. plus = new Thread(new Runnable() {
  73. @Override
  74. public void run() {
  75. while (cap > 0) {
  76. try {
  77. Thread.sleep(6000);
  78. } catch (InterruptedException e) {
  79. break;
  80. }
  81. cap += 10;
  82. System.out.println(cap);
  83. time += 6;
  84. }
  85. }
  86. });
  87.  
  88. drink.start();
  89. plus.start();
  90. }
  91. }
Add Comment
Please, Sign In to add comment