Advertisement
ksoltan

JM Chapter 10 #15

Mar 11th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. Write a method that tests whether a given string contains only digits.
  2.  
  3. JM Chapter 10 #15
  4.  
  5. "12345", true
  6. "123h5", false
  7. "", false
  8. "1", true
  9. "23fr", false
  10. "fuwge", false
  11. "o", false
  12. "019347019", true
  13. "ofihwioef1924109471902fhiohfio", false
  14. "19824612894hi12481924619a124891924", false
  15. "89198498189", true
  16.  
  17. private boolean isNumerical(String str){
  18. if(str.length() < 1)
  19. return false;
  20. for (int i = 0; i < str.length(); i++) {
  21. if(!Character.isDigit(str.charAt(i)))
  22. return false;
  23. }
  24. return true;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement