2016-06-06 5 views
0

블랙 잭 게임을하려고하는데 11이 너무 높으면 "ACE"의 값을 1로 변경하는 방법을 모르겠습니다. 저는 이제 Arraylist를 찾아 A의 가치를 바꾸려고 노력하고 있습니다. 그러나 Arraylist에 얼마나 많은 A가 있는지 어떻게 알 수 있습니까?특정 요소에 대한 Arraylist 모양

 while (getPointsPC() < 17 || getPointsPC() < getPointsPL()){ 

      int acees = 0; 

      random = bj.getRandom(); 
      CardsPC.add(bj.getCard(random)); 
      setPointsPC(random); 

      lblPointsPC.setText("Points Dealer: " + Integer.toString(getPointsPC())); 

      String text = CardsPC.get(0); 
      for(int i = 1; i < CardsPC.size(); i++){ 
       text = text + ", " + CardsPC.get(i); 
      } 

      if (CardsPC.contains("A") && getPointsPC() > 21 && acees < CardsPC.**HOW_MUCH_A's???**){ 
       setPointsPC(13); 
       acees++; 
      } 

      lblCardsPC.setText(text); 

     } 
+2

내가 알고하지 않았다 "는 [엉덩이] (https://c1.staticflickr.com/3/2651/3892880140_52ec991129.jpg)"수 있었다. "ACE"를 원하셨습니까? – Andreas

답변

1

귀하의 CardsPC은 귀하의 언급 된 ArrayList입니까? 그냥 설정 카운터 변수 :

String text = ""; 
int counter = 0; 
for(int i = 0; i < CardsPC.size(); i++){ 
    text = text + (i > 0 ? ", " : "") + CardsPC.get(i); 
    if (CardsPC.get(i).contains("A")) { // or use equals, base on your input. 
      counter++; 
      // do something with found "A" element if you want. 
    } 
} 
관련 문제