Ad
  • Default User Avatar

    s.charAt(i) - returns the character code from the ASCII table. The number codes are sequential: '0', '1', '2' ... '9' or in the form of code 48, 49, 50 ... 57. For example, "2".charAt(0) = '2' or 50 (character value and code), but we need to get the number 2,to do this, we just need to subtract the character code '0' (48). "2".charAt(0) - '0' = 50 - 48 = 2