Advertisement
Guest User

Bad Code for Kevin Lol

a guest
May 2nd, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class ThreadTest {
  5. static final T[] t = new T[100];
  6. static boolean m = false;
  7. public static void main(String[] args) throws InterruptedException {
  8. for (int i=0;i<100;i++) {
  9. t[i] = new T(i);
  10. }
  11. for (int i=0;i<100;i++) {
  12. t[i].start();
  13. }
  14. while (true) {
  15. for (int i = 0; i < 100; i++){System.out.print(t[i].x + ",");}
  16. System.out.println();
  17. try{Thread.sleep(1000);}catch(Exception e){}
  18. }
  19. }
  20. }
  21. class T extends Thread {int c,x;
  22. public T(int i){c=i;x=(int)(Math.random()*100);}
  23. public void run() {
  24. T a = ThreadTest.t[c-1 == -1 ? 99 : c-1];
  25. T b = ThreadTest.t[c+1 == 100 ? 0 : c+1];
  26. while (true) {
  27. if (ThreadTest.m)
  28. if (a.x < x && b.x < x)
  29. x--;
  30. else if (a.x > x && b.x > x)
  31. x++;
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement