问答详情
源自:7-1 简易扑克牌游戏

创建扑克牌时List add方法和预想的不一样

public void pokerSetUp(){

Poker pokerCard = new Poker();

List pokerList = new ArrayList();

String[] pokerstr1 = {"黑桃","红桃","梅花","方片"};

String[] pokerstr2 = {"2","3","4","5","6","7","8","9","10","J","Q","k"};

System.out.println("----------创建扑克牌----------");

for(int i=0;i < 4;i++){

for(int j=0;j < 12;j++){

pokerCard.pokercard1 = pokerstr1[i];

// System.out.println(pokerstr1[i]);

// System.out.println(pokerCard.pokercard1);

pokerCard.pokercard2 = pokerstr2[j];

// System.out.println(pokerstr2[j]);

// System.out.println(pokerCard.pokercard2);

pokerList.add(pokerCard);

}

}

System.out.println("----------扑克牌创建成功----------");

System.out.println("为:");

/**

* 通过For each访问List

*/

for (Object obj : pokerList) {

Poker cr = (Poker) obj;

System.out.print(cr.pokercard1 + cr.pokercard2 + " ");

}

}


提问者:plorzzz 2016-12-13 09:40

个回答

  • TiGer196
    2017-02-04 21:51:51

    存错了,取错了

  • plorzzz
    2016-12-13 09:44:58


    // System.out.println(pokerstr1[i]);

    // System.out.println(pokerCard.pokercard1);

    测试发现在输入List之前我的每个元素都是正确的 但是使用add在循环中添加后用For each遍历输出出来全是 方片k

    头疼 56个方片k ....