Hi getting an error and don't know why. Here my code for a challenge.
public class Solution {
static void displayPathtoPrincess(int n, String [] grid){
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int m;
m = in.nextInt();
String grid[] = new String[m];
for(int i = 0; i < m; i++) {
grid[i] = in.next();
}
int[] x;
x = new int[m-1];
x[0] = 0;
String p;
String single[];
single = new String[(m*m)];
for(int i = 0; i < (m); i++){
for(int b = 0; b <= m; b++){
single[b] = (grid[i].split("(?!^)"));
System.out.println(p);
}
}
displayPathtoPrincess(m,grid);
}
}
The code is not neat or anywhere near complete but when I run it I get this error:
Solution.java:29: error: incompatible types
single[b] = (grid[i].split("(?!^)"));
^
required: String
found: String[]
1 error
I then tried using a regular string thats not an array didnt work. I then tried to just put in a string where grid[i]
is and that also didnt work. Im stuck any help is appreciated!
The
split()
method returns an arrayString[]
and you are trying to insert array intoString
.Just edit your code to this :