if (!pos[1].equals("")) {
String name = pos[1];
System.out.println(name);
int p = 0;
for (int i = name.length() - 1; i>0; i--){
if (name.charAt(i)==' ') {
p = i;
break;
}
System.out.println(p);
rank[1] = Integer.parseInt(name.substring(p).trim());
}
}
In the code, int p is set as i in the if block. However, when it is accessed outside the if block the value still remains 0 and not the value i set in the if condition.