Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- static int cap = 100;
- static int time = 0;
- static Thread plus;
- public static void main(String[] args) throws InterruptedException {
- Thread drink = new Thread(new Runnable(){
- @Override
- public void run() {
- while (cap > 0) {
- try {
- Thread.sleep(3000);
- } catch (InterruptedException e) {}
- cap -= 10;
- System.out.println(cap);
- time += 3;
- }
- Thread.currentThread().interrupt();
- plus.interrupt();
- System.out.println(time);
- }
- });
- plus = new Thread(new Runnable(){
- @Override
- public void run() {
- while (cap > 0) {
- try {
- Thread.sleep(6000);
- } catch (InterruptedException e) {}
- cap += 10;
- System.out.println(cap);
- time += 6;
- }
- Thread.currentThread().stop();
- }
- });
- drink.start();
- plus.start();
- }
- }
- public class Main {
- static int cap = 100;
- static int time = 0;
- static Thread plus;
- public static void main(String[] args) {
- Thread drink = new Thread(new Runnable() {
- @Override
- public void run() {
- while (cap > 0) {
- try {
- Thread.sleep(3000);
- } catch (InterruptedException ignored) {
- }
- cap -= 10;
- System.out.println(cap);
- time += 3;
- }
- plus.interrupt();
- System.out.println(time);
- }
- });
- plus = new Thread(new Runnable() {
- @Override
- public void run() {
- while (cap > 0) {
- try {
- Thread.sleep(6000);
- } catch (InterruptedException e) {
- break;
- }
- cap += 10;
- System.out.println(cap);
- time += 6;
- }
- }
- });
- drink.start();
- plus.start();
- }
- }
Add Comment
Please, Sign In to add comment