Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- /*Please dont change class name, Dcoder
- and class must not be public*/
- //Compiler version JDK 1.8
- class Dcoder {
- public static void main(String args[]) {
- Suma s = new Suma();
- Thread sume = new Thread(s);
- Ispis ispis = new Ispis(s);
- int p = 10;//mrzi me da kucam ono sa tastature
- sume.start();
- ispis.start();
- while(p!=0) {
- p--;
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- return;
- }
- }
- ispis.interrupt();
- sume.interrupt();
- try {
- ispis.join();
- sume.join();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- class Suma implements Runnable {
- public static volatile int last;
- public Suma() {
- this.last = 0;
- }
- public void run() {
- int i = 0;
- while (true) {
- i += i + 1;
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- return;
- }
- last = i;
- }
- }
- }
- class Ispis extends Thread {
- Suma s;
- public Ispis (Suma s) {
- this.s = s;
- }
- public void run() {
- while(true) {
- System.out.println(""+s.last);
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement