Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Vezbe1 implements Runnable {
- public static void main(String[] args) {
- Thread threads[] = new Thread[5];
- for(int i = 0; i < 5; i++) {
- threads[i] = new Thread(new Vezbe1(), "n"+i);
- threads[i].start();
- }
- Scanner s = new Scanner(System.in);
- while(!s.next().equals("Kraj")) {
- }
- for(int i = 0; i < 5; i++) {
- threads[i].interrupt();
- }
- s.close();
- }
- @Override
- public void run() {
- switch(Thread.currentThread().getName()) {
- case "n0": {
- long p = 0;
- long d = 1;
- for(int i = 1; i <= 50 && !Thread.interrupted(); i++) {
- long t = p;
- p=d;
- d=t+p;
- System.out.println(Thread.currentThread().getName() + ": " + p);
- }
- }
- break;
- case "n1": {
- for(int i = 1; i <= 50 && !Thread.interrupted(); i++) {
- System.out.println(Thread.currentThread().getName() + ": " + i*i);
- }
- }
- break;
- case "n2": {
- for(int i = 1; i <= 50 && !Thread.interrupted(); i++) {
- System.out.println(Thread.currentThread().getName() + ": " + 2*(i+1));
- }
- }
- break;
- case "n3": {
- for(int i = 1; i <= 50 && !Thread.interrupted(); i++) {
- System.out.println(Thread.currentThread().getName() + ": " + 2*i+1);
- }
- }
- break;
- case "n4": {
- long f = 1;
- for(int i = 1; i <= 50 && !Thread.interrupted(); i++) {
- f*=i;
- System.out.println(Thread.currentThread().getName() + ": " + f);
- }
- }
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement