Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Write a method that tests whether a given string contains only digits.
- JM Chapter 10 #15
- "12345", true
- "123h5", false
- "", false
- "1", true
- "23fr", false
- "fuwge", false
- "o", false
- "019347019", true
- "ofihwioef1924109471902fhiohfio", false
- "19824612894hi12481924619a124891924", false
- "89198498189", true
- private boolean isNumerical(String str){
- if(str.length() < 1)
- return false;
- for (int i = 0; i < str.length(); i++) {
- if(!Character.isDigit(str.charAt(i)))
- return false;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement