Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
入力が文字列「783」で、input.charAt(i) を介して文字列から文字を取得し続ける場合、同等の整数を取得する唯一の方法はCharacter.digit(input.charAt(i),10)??
Character.digit(input.charAt(i),10)
もっと簡単な表現はありますか?
これが最も安全な方法ですが、0〜9はUnicode 10進値では48〜57であるため、文字値から48を引くこともできます。
int c = input.charAt(i) - 48;
ただし、文字が数字以外の場合(たとえば、)、これはもちろん非現実的な結果を返し'A' - 48ます17。
'A' - 48
17