use this code
public class Numbers {
public static void main(String[] args) {
int firstDigit = 0;
int secondDigit = 0;
int thirdDigit = 0;
int count = 0;
for (int i = 0; i < 1000; i++) {
if (i == 9) {
count++;
}
if (i > 10 && i < 100) {
secondDigit = i % 10;
if (secondDigit == 9) {
count++;
}
firstDigit = i / 10;
if (firstDigit == 9) {
count++;
}
}
if (i > 100) {
thirdDigit = i % 10;
if (thirdDigit == 9) {
count++;
}
firstDigit = i / 100;
if (firstDigit == 9) {
count++;
}
secondDigit=i%100;
secondDigit=secondDigit/10;
if (secondDigit == 9) {
count++;
}
}
}
System.out.println(count);
}
}
"Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 1"
means that array does not go that far.
new array[10];
//contains 10 numbers.
array[15];
//calling 15th number will give exception.