日期:2014-05-17 浏览次数:20710 次
package test; import java.util.ArrayList; import java.util.List; public class Test8 { public static void main(String[] args) { String[] s1={"?","?","?","?"}; String[] s2={"2","3","4","5","6","7","8","9","10","J","Q","K","A"}; String str; List cards= new ArrayList();;// str.split("[,,]"); //将点数组合成52张扑克牌 for(int j=0; j<=12; j++){ for(int i=0; i<4; i++){ str = s1[i]+s2[j]; cards.add(str); //将组合的字符串添加到List集合中 } } //System.out.println(cards); //输出所有的扑克牌 String[] str2 ={"甲", //东边 "乙", //南边 "丙", //西边 "丁" //北边 }; int i=0; while(i<cards.size()){ int k=i; //避免i++,影响k的取值为i+1 System.out.print(str2[i++%4]+":"+cards.get(k)+" "); if( i%4 == 0){ System.out.println(); } } } } 执行结果: 甲:?2 乙:?2 丙:?2 丁:?2 甲:?3 乙:?3 丙:?3 丁:?3 甲:?4 乙:?4 丙:?4 丁:?4 甲:?5 乙:?5 丙:?5 丁:?5 甲:?6 乙:?6 丙:?6 丁:?6 甲:?7 乙:?7 丙:?7 丁:?7 甲:?8 乙:?8 丙:?8 丁:?8 甲:?9 乙:?9 丙:?9 丁:?9 甲:?10 乙:?10 丙:?10 丁:?10 甲:?J 乙:?J 丙:?J 丁:?J 甲:?Q 乙:?Q 丙:?Q 丁:?Q 甲:?K 乙:?K 丙:?K 丁:?K 甲:?A 乙:?A 丙:?A 丁:?A