我有一个运行良好的 java 程序,但不知何故,加班它失败了。我真的不知道怎么做,也不知道为什么,所以我希望一双新的眼睛能帮助解决这个问题。请帮忙,谢谢!该程序是一个简单的“扑克”代码,从一副牌中随机输出 5 张牌。
该程序在我第一次运行时正在运行,但由于某种奇怪的原因它不再运行。
I keep getting the errors...
"cannot resolve symbol rank.length",
"cannot resolve symbol suit.length",
"Package java.Random does not exist"
该程序:
import java.Random.*;
import java.io.*;
import java.util.*;
public class Poker {
public static void main(String[] args) {
//initialize variables
int suits = suit.length;
int ranks = rank.length;
int n = suits * ranks;
//counter
int m = 5;
// create a deck of 52 cards
String[] suit = { "Clubs", "Diamonds", "Hearts", "Spades" };
String[] rank = { "2", "3", "4", "5", "6", "7", "8", "9", "10",
"Jack", "Queen", "King", "Ace"
};
// initialize deck
String[] deck = new String[n];
for (int i = 0; i < ranks; i++) {
for (int j = 0; j < suits; j++) {
deck[suits*i + j] = rank[i] + " of " + suit[j];
}
}
// create random 5 cards
for (int i = 0; i < m; i++) {
int r = i + (int) (Math.random() * (n-i));
String t = deck[r];
deck[r] = deck[i];
deck[i] = t;
}
// print results
for (int i = 0; i < m; i++){
System.out.println(deck[i]);
}
}
}