Java multidimensional array and scanner novice Q
        Posted  
        
            by 
                Max
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Max
        
        
        
        Published on 2012-04-06T05:25:11Z
        Indexed on 
            2012/04/06
            5:29 UTC
        
        
        Read the original article
        Hit count: 272
        
java
|multidimensional-array
I'm new to Java and trying to in essence implement a grid with a character, and if the user inputs 'w' 'a' 's' or 'd' the character moves up/down/left/right within the plane.
I created a multidimensional array sized 10x10 public static String[][] grid = new String[10][10];
And then just used a for loop to print "*"s in a 10x10 grid, except for grid[a][b] which is equal to character "A" i.e. my thing to be moved around.
That seemed to work alright, then I needed to detect the 'wasd' input from the user so I set up a:
Scanner in = new Scanner (System.in);
        while (in.hasNext())
And I had then:
String s = in.next();
char ch = s.charAt(0);
switch (ch)
but I couldn't make this work, and it wasn't because I didn't complete the "switch" statement, I did, I just see it void copying and pasting the entire thing.
I'm sure its incredibly easy slight thing I am missing, can you please point it out for me?
© Stack Overflow or respective owner