public class puke
{
private card[] m_card = null;
private String[] colors = {"红桃","黑桃","方片","草花"};
private int[] values = {1,2,3,4,5,6,7,8,9,10,11,12,13};
public puke()
{
m_card = new card[52];
for(int i = 0; i < colors.length;i++)
{
for (int j = 0; j < values.length; j++)
{
m_card[i*13+j]=new card(values[j], colors[i]);
}
}
}
public void outCards()
{
for(int i = 0; i < m_card.length; i++)
{
if(i%13==0)
{
System.out.println();
}
System.out.print(m_card[i].toString()+" ");
}
}
}
public class card
{
private int shuzi;
private String color;
public card(int shuzi,String color)
{
this.shuzi=shuzi;
this.color=color;
}
@Override
public String toString()
{
String str="";
switch (shuzi)
{
case 1:
{
str="A";
break;
}
case 11:
{
str="J";
break;
}
case 12:
{
str="Q";
break;
}
case 13:
{
str="K";
break;
}
default:
{
str=String.valueOf(shuzi);
}
}
return color+str;
}
} public static void main(String[] args) {
// write your code here public static void main(String[] args) {
// write your code here
//Card card = new Card(13,"方片");
//System.out.println(card);
puke p = new puke();
p.outCards();
}
}
java练习 扑克牌
最新推荐文章于 2022-07-14 08:20:31 发布