I've read through a number of similar threads, but in my nOObishness can't seem to figure out how I can apply the answers to my code. Sorry...
When running the code below I'm getting the error: java.lang.StringIndexOutOfBoundsException: String index out of range:
The outcome of the program is okay. I'm getting all the capitals from the string that I have entered with the scanner. But the error message is kinda in the way.
Any help is very appreciated! Thanks in advance!
import java.util.Scanner;
public class TestClass {
public static void main(String[] args) {
Scanner in3 = new Scanner(System.in);
System.out.print("Enter a senctence with capitals: ");
String inputString = in3.nextLine();
int stringLength = String.valueOf(inputString).length();
int i = 0;
while (i <= stringLength)
{
int subsStart = i;
int subsEind = i + 1;
String stringToCheck = inputString.substring(subsStart, subsEind);
char letterToCheck = stringToCheck.charAt(0);
if (Character.isUpperCase(letterToCheck))
{
System.out.println(letterToCheck);
}
i++;
}
in3.close();
}
}