This code should invert a string given by the first argument, but has a compilation error
public class ex4 {
public static void main (String args[]) throws IOException {
int strlength=length(args);
InvertString(args, strlength, 0);
}
public static int length(String args[]) {
int i=0;
int count=0;
while(Character.isLetter(args[0].charAt(i))) {
count++;
i++;
}
return count;
}
public static void InvertString(String args[], int i, int x){
char a= args[0].charAt(x);
args[0].charAt(x)=args[0].charAt(i-1-x);
args[0].charAt(i-1-x)=a;
x++;
if(x<(i/2)) InvertString(args,i,x);
}
}
The compilation error is as follows:
ex4.java:27: error: unexpected type required: variable found: value ex4.java:28: error: unexpected type required: variable found: value