This site requires JavaScript, please enable it in your browser!
Greenfoot back
xxX_Muffin.man_Xxx
xxX_Muffin.man_Xxx wrote ...

2015/2/24

Need help with 2D arrays

xxX_Muffin.man_Xxx xxX_Muffin.man_Xxx

2015/2/24

#
The idea of the code is that this code below is all in an act method in the world. When the button Answerbutton1 is clicked it prompts the user to input 2 strings. It then changes the strings into characters to shorten them to the 1 letter. The next bit of code is where i try to add each of the letters and symbols in a pairing into the 2d array. Then the next if statement is a button where it outputs first the letter then the symbol. However when i click it all it outputs is just null repeatedly and none of the pairings at all after ive entered them and clicked the button
String[][] array = new String [26] [2];
        int  n = -1;

if(Greenfoot.mouseClicked(Answerbutton1))
        {

            String symbol = JOptionPane.showInputDialog("Enter the symbol which you would like to change");
            String letter = JOptionPane.showInputDialog("Enter the letter which you would like to input");

            char symbol1 = symbol.charAt(0);
            char letter1 = letter.charAt(0);

            String USERsymbol = Character.toString(symbol1);
            String USERletter = Character.toString(letter1);

 

            n = n + 1;
            array [n] [0] = USERletter;
            array [n] [1] = USERsymbol;
}

if(Greenfoot.mouseClicked(Pairings))
        {    
             
            for (int i=0 ; i <= 5; i++)
            {
                for(int j=0 ; j <= 1 ; j++)
                {

                    System.out.println(array [i] [j]);

                }
            }
        }
I would like to know what's wrong with the code.
Hersov Hersov

2015/2/24

#
This is an interesting way of approaching this task, I would have done it in a different way. Maybe fix the bus and then come to feed the chickens instead of doing both at the same time. Hope my analogy helps!
davmac davmac

2015/2/24

#
I suggest nobody need to respond to this discussion, as unfortunately I've had to disable the poster's account due to their posting offensive material (in a separate discussion).
You need to login to post a reply.