如何使多个字符串等于一个值 (Java)

How to make multiple Strings equal to one value (Java)

我想要这样的东西:

String Aa, Eb, Cc, Dd, Be, Ff = "1";
String Ba, Db, Ac, Ed, Fe, Cf = "2";
String Ea, Cb, Bc, Fd, Ae, Df = "3";
String Da, Ab, Fc, Bd, Ce, Ef = "4";
String Fa, Bb, Ec, Cd, De, Af = "5";
String Ca, Fb, Dc, Ad, Ee, Bf = "6";

但这不起作用,它会生成最后一个(Ff、Cf、Df、Ef、Af 和 Bf),但忽略之前的那些。另外,我不想制作数组,因为挑战(我在 class 中)是在不使用任何形式的数组的情况下编写数独游戏。

你必须初始化每个字符串,像这样:

String Aa = "1", Eb = "1", Cc = "1", Dd = "1", Be = "1", Ff = "1";
...

另一种选择是:

String Aa, Eb, Cc, Dd, Be, Ff;
Aa = Eb = Cc = Dd = Be = Ff = "1";
...

数组对你无效,

所以你可以

喜欢

String Aa = "1", Eb = "1"....;

String Aa = "1";
String Eb = "1";
...

比java语言中没有定义的要灵活得多