pred[] is a char array taken as input from the user. the expected input is in form predicate(param1,param2). this while loop is to detect the start and end indices of predicate, param1, and param2 but for some reason it is giving an exception.
int k =0;
while(pred[k]!="\0"){
System.out.println("k="+k);
if ("(".equals(pred[k])) {
param1_st = k + 1;
pred1_end = k - 1;
}
if (",".equals(pred[k])) {
param1_end = k - 1;
param2_st = k + 1;
}
if (")".equals(pred[k])) {
param2_end = k - 1;
}
k++;
}
output:
Enter a predicate 1
abd(sd,sdf)
Entered predicate is: abd(sd,sdf)
Enter a predicate 2
abd(x,db)
Entered predicate is:
abd(x,db)k=0
k=1
k=2
k=3
k=4
k=5
k=6
k=7
k=8
k=9
k=10
Exception in thread "main"
java.lang.ArrayIndexOutOfBoundsException:11
at unification.Unif.main(Unif.java:41)