Search code examples
javastringinitializing

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


I want something like this:

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";

But that doesn't work, It makes the last ones (Ff, Cf, Df, Ef, Af, and Bf), but the ones before that get ignored. Also, I don't want to make an array because the challenge (I'm in a class) was to program sudoku without using any forms of arrays.


Solution

  • You will have to initialize each String, like this:

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

    An alternative would be this:

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