I need to complete the method allDigits using isDigit that i wrote, that when passed a valid String, returns true if all characters of the String are digits, and false otherwise.
So far i have:
public static boolean isDigit (char ch){
if (ch >= '0' && ch <= '9')
return true;
return false;
}
public static boolean allDigits(String s){
for (int i =0; i<s.length(); i++)
if(isDigit(s.charAt(i)) == true)
return true;
return false;
}
But this returns true if just say
public static void main(String[] args) {
String s = "abc123";
System.out.println(allDigits(s));
}
OUTPUT: true
However should return false
ALSO: Is my code efficient? I feel like theres an easier way. Any help is appreciated thanks