我试图创建一副具有81张独特牌的牌组(基于SET游戏)。我试图通过使用三个广义for循环来实现这一点。现在,我有三个具有功能(形状,颜色,图案)的字符串数组。但是,在循环中添加println
语句后,我发现只创建了只有一种模式的红卡。
ArrayList<Card> deck = new ArrayList<Card>();
static public Deck create() {
Deck deck = new Deck();
String[] shapes = new String[] { "diamond", "squiggly", "oval",
"double diamond", "double squiggly", "double oval",
"triple diamond", "triple squiggly", "triple oval" };
String[] colors = new String[] { "red", "green", "purple" };
String[] patterns = new String[] { "stripes", "filled in", "outlined" };
// Shapes
for (String shape : shapes) {
System.out.println(shape);
// Colors
for (String color : colors) {
System.out.println(color);
// Patterns
for (String pattern : patterns) {
System.out.println(pattern + "\n");
Card card = new Card(shape, color, pattern);
deck.deck.add(card);
break;
}
break;
}
}
return null;
}
这是输出:
diamond
red
stripes
squiggly
red
stripes
oval
red
stripes
double diamond
red
stripes
double squiggly
red
stripes
double oval
red
stripes
triple diamond
red
stripes
triple squiggly
red
stripes
triple oval
red
stripes
现在,它应该用每个单独的图案和形状创建所有形状。我完全迷失了这一点,我将不胜感激任何帮助!
答案 0 :(得分:2)
答案 1 :(得分:2)
删除break;
部分。您在第一次执行后结束内部for循环。
答案 2 :(得分:0)
删除break
语句,因为它们会在您设法迭代数据之前终止循环。