58,453
社区成员
发帖
与我相关
我的任务
分享
package com.demo;
public class project_3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int number = (int)(Math.random()*52 + 1);
System.out.println("number="+number);
int[][] poker;
poker = new int[5][14];
int i = 0;
int j = 0;
poker[0][0] = 1;
poker[1][0] = 14;
poker[2][0] = 27;
poker[3][0] = 40;
while (i < 4) {
while (j < 13) {
poker[i][j + 1] = poker[i][j] + 1;
j++;
}
j = 0;
i++;
}
int m = 0;
int n = 0;
i=0;//设置i=0,否则此时i=4
j=0;//设置i=0 修改了这里-------------
do {
while (j < 13) {
if (poker[i][j] == number) {
m = i;
n = j;
}
j++;
}
j = 0;
i++;
}
while (i < 4);
System.out.println("The randomNumber is " + number);
figure(n);
color(m);
}
public static void figure(int n) {
if (n > 0 && n < 10) System.out.println("The number is " + n + 1);
if (n == 0) System.out.println("The number is " + "Ace");
else if (n == 10) System.out.println("The number is " + "Jack");
else if (n == 11) System.out.println("The number is " + "Queen");
else if (n == 12) System.out.println("The number is " + "King");
}
public static void color(int m) {
if (m == 0) System.out.println("The color is Clubs");
else if (m == 1) System.out.println("The color is Diamond");
else if (m == 2) System.out.println("The color is Heart");
else if (m == 3) System.out.println("The color is Spades");
}
}