I’m having some trouble with my code, I am trying to test if a position in a char is equal to an integer. The way I have it setup is like so:
for(int i = 0; i < str.length(); i++) {
if(str.charAt(i) == '[1234567890]') {
System.out.println(str);
}
}
However I’m getting the error “unclosed character literal” when I try to compile. Does anyone know why I’m getting an error, or can explain a more simple way to do this?
Try:
You have to check that every character is a digit to check if your string contains and integer.