I'm stuck with this and can't find a solution. Get error of Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 11.
Can anyone help to solve this? My code:
public static void main(String[] args) {
try {
Scanner sc = new Scanner(new File("Testing.txt"));
int i = 0;
while(sc.hasNext()){
String line = sc.nextLine();
char needle = line.charAt(i);
while(i < line.length()){
if(Character.isUpperCase(needle)) {
while(needle != ' '){
System.out.print(needle);
i++;
needle = line.charAt(i);
}
System.out.println(needle);
}
else{
i++;
needle = line.charAt(i);
}
}
}
}
catch (FileNotFoundException e) {
System.out.println(e.getMessage());
}
}