First, this is for a school class. This is my program:
import java.util.*;
public class Exitearly1 {
public static void main(String[] args) {
Scanner kbinput = new Scanner(System.in);
System.out.println("Please input your name: ");
String name = kbinput.next();
int count = 0;
while (count < name.length()) {
count++;
int res = name.charAt(count);
if ((res == 'a') || (res == 'A'))
continue;
System.out.println(name.charAt(count));
}
System.out.println("Name with no A's");
}
}
It prints what I am inputting (Andrea) without A's like it is suppose to, but after doing so instead of printing out that last line it gives me this in the output:
n
d
r
e
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 6
at java.lang.String.charAt(String.java:686)
at Exitearly1.main(Exitearly1.java:13)
I tried many different ways to fix it with nothing changing it, I am coming here because I asked my teacher how to fix it, and she only told me what was wrong with it which I already knew.