JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 新手區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
作者 電腦猜數字遊戲 無法跑完
bear8708





發文: 1
積分: 0
於 2018-06-06 12:47 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Post is deleted

bear8708 edited on 2018-06-07 11:07
reply to postreply to post
作者 Re:電腦猜數字遊戲 無法跑完 [Re:bear8708]
lasaka





發文: 32
積分: 0
於 2018-06-07 06:59 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
while (turn)
卡死在迴圈中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
class Lock {
    public static Lock obj = new Lock();
    static boolean done = false, turn = false;
    boolean AOK = false;
    static int n = 0;
    static int aba = 0;
    static int[] ab = new int[9877];
    static String str = "";
    String s1 = "", s2 = "", s3 = "";
    static int a1 = 0, b1 = 0;
    int tra = 0;
 
    public void a() {
      while (!turn) {
        try {
          Thread.sleep(1);
        } catch (Exception x) {
        }
      }
      if (tra == aba) {
        AOK = true;
        System.out.println("A=" + "恭喜答案拉");
        str = "4A0B";
        done = true;
      } else {
        ab[tra] = 1;
        s1 = Integer.toString(tra);
        s3 = Integer.toString(aba);
        a1 = 0;
        b1 = 0;
 
        for (int i = 0; i < 4; i++) {
          if (s1.charAt(i) == s3.charAt(i)) {
            a1++;
          }
          for (int p = 0; p < 4; p++) {
            if (i != p) {
              if (s1.charAt(i) == s3.charAt(p))
                b1++;
            }
          }
        }
        AOK = true;
        System.out.println("A=" + a1 + "A" + b1 + "B");
        
      }
      set_turn();
    }
 
    public void b() {
      while (turn) {
        try {
          Thread.sleep(1);
        } catch (Exception x) {
        }
      }
      if (str != "4A0B") {
        if (AOK == true) {
          for (int j = 1023; j <= 9876; j++) {
            int a2 = 0, b2 = 0;
            s2 = Integer.toString(j);
            for (int k = 0; k < 4; k++) {
              if (s1.charAt(k) == s2.charAt(k)) {
                a2++;
              }
            }
            for (int K = 0; K < 4; K++) {
              for (int p = 0; p < 4; p++) {
                if (K != p) {
                  if (s1.charAt(K) == s2.charAt(p))
                    b2++;
                }
              }
            }
            if (a2 != a1 || b2 != b1) {
              ab[j] = 1;
            }
          }
        }
        boolean bl = false;
        do {
          for (int i = 1023; i <= 9876; i++) {
            if (ab[i] != 1) {
              tra = i;
              System.out.println("B=" + tra);
              bl = true;
              break;
            }
          }
        
        } while (bl != true);
      }
      set_turn();
    }
 
    public synchronized void set_turn() {
      turn = !turn;
    }
  }


reply to postreply to post
作者 Re:電腦猜數字遊戲 無法跑完 [Re:lasaka]
bear8708





發文: 1
積分: 0
於 2018-06-07 11:18 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
謝謝你的幫助!!

reply to postreply to post
» JWorld@TW »  Java 新手區

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8