I have ran into a bit of a dilemma, I need to just change my array so that it is read in as one string per line instead of a single character; however when I do so it completely changes my whole program. I can provide more code if needed.
I have tried hasNext and everything else I can think of. I have placed an example of what I mean down below
If the user enters : 2
than the user wants to enter O,X,O,X but I want to make it so they can still enter characters but multiple on each line. I want them to be able to enter OX on one line and OX on the nextline.
public static void main(String[] args) {
// TODO code application logic here
Scanner kbd = new Scanner(System.in);
//int[][] totalOpenness = new int[n][n];
System.out.println("ENTER A SINGLE INTEGER: ");
int n = kbd.nextInt();
int[][] totalOpenness = new int[n+1][n+1];
char[][] mazeValue = new char[n + 1][n + 1];
System.out.println("ENTER A PATH: ");
for (int i = 0; i < mazeValue.length; i++) {
for (int j = 0; j < mazeValue[i].length; j++) {
if (i == 0 || j == 0 || i == n + 1 || j == n + 1)
mazeValue[i][j] = 'X';
else {
mazeValue[i][j] = kbd.next().charAt(0);
}
}
}
Aucun commentaire:
Enregistrer un commentaire