日期:2014-05-20 浏览次数:20715 次
import java.util.Random; public class Read { public static void main(String[] args) { System.out.println(getPai()); } private static String getPai() { Random r = new Random(); int i = r.nextInt(54); return getName(i); } private static String getName(int i) { if (i == 53) { return "小王"; } else if (i == 54) { return "大王"; } int p = i % 13; int c = (i - 1) / 13; return getColor(c) + getPoint(p); } private static String getColor(int c) { String color = ""; switch (c) { case 0: color = "方块"; break; case 1: color = "梅花"; break; case 2: color = "黑桃"; break; default: color = "红桃"; break; } return color; } private static String getPoint(int p) { String point = ""; if (p == 0) { point = "K"; } else if (p < 11) { point = String.valueOf(p); } else if (p == 11) { point = "J"; } else { point = "Q"; } return point; } }