Instructions: Given a string, determine if it is an integer. For example the string “123” is an integer, but the string “hello” is not.
It is an integer if all of the characters in the string are digits.
Return true if it is an integer, or false if it is not.
Hint: There is a method Character.isDigit() that takes a char as an argument and returns a boolean value.
What I have so Far:
public boolean isInteger(String str) {
if(Character.isDigit(str.charAt(0)) == 0) {
return false;
}
for (int i = 0; i < str.length(); i++) {
if(Character.isDigit(str.charAt(i))) {
break;
} else {
return false;
}
}
return true;
}
I'm having an issue with returning a boolean value for the string "101" and no string at all (" ")