简体   繁体   中英

How to input a string one charecter at a time into a 2d array

So i have a string and i need to put it into a 2d array this is what i have so far.

mazeString = ".............."    
char[][] mazeArray = new char [50][30];
         for (int i = 0; i < (height*2)-1; i++){
           for (int j = 0; j < (width*2)-1; j++){
              mazeArray[j][i] = mazeString.next();
           }

         }

Like said in the comments, mazeString is declared and initialized as a String Literal. All .next() methods are reserved for Scanner objects. Java doesn't let you use scan

So i figured it out.

while (input.hasNextLine()) {
      mazefile = mazefile + input.nextLine();
    }


for (int i = 0; i < (height*2)+1; i++){
       for (int j = 0; j < (width*2)+1; j++){
          mazeArray[i][j] = mazefile.charAt(counter);
          counter++;
       }
     }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM