In this program allDigits(String): accepts a string and returns true if EVERY character is a digit, otherwise false.
The code seems really simple but i seem not to be getting it here is my code:
//this should produce a false statement because not all characters are digits
public class Test {
public static void main(String[] args) {
String s = "1were";
System.out.print(allDigits(s));
}
public static boolean allDigits(String s) {
int sum = 0;
for (int i = 0; i < s.length(); i++) {
if( s.charAt(i) > 0 || s.charAt(i) <= 9) {
return true;
}
}
return false;
}
}
P.S. Im a beginner so let me know if im going in the right direction with this. Thank you