Guest User

Untitled

a guest
Feb 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. public int strToInt(String str) {
  2. int i=0;
  3. int num = 0;
  4. boolean isNeg = false;
  5.  
  6. if(str.charAt(0)=='-') {
  7. isNeg=true;
  8. i=1;
  9. }
  10.  
  11. while (i<str.length()) {
  12. num *=10;
  13. num += str.charAt(i++) -'0';
  14. }
  15.  
  16. if(isNeg)
  17. num = -num;
  18.  
  19. return num;
  20.  
  21. }
Add Comment
Please, Sign In to add comment