<small id='dhoc8'></small><noframes id='dhoc8'>

    <tfoot id='dhoc8'></tfoot>
    <i id='dhoc8'><tr id='dhoc8'><dt id='dhoc8'><q id='dhoc8'><span id='dhoc8'><b id='dhoc8'><form id='dhoc8'><ins id='dhoc8'></ins><ul id='dhoc8'></ul><sub id='dhoc8'></sub></form><legend id='dhoc8'></legend><bdo id='dhoc8'><pre id='dhoc8'><center id='dhoc8'></center></pre></bdo></b><th id='dhoc8'></th></span></q></dt></tr></i><div id='dhoc8'><tfoot id='dhoc8'></tfoot><dl id='dhoc8'><fieldset id='dhoc8'></fieldset></dl></div>
      <bdo id='dhoc8'></bdo><ul id='dhoc8'></ul>

    <legend id='dhoc8'><style id='dhoc8'><dir id='dhoc8'><q id='dhoc8'></q></dir></style></legend>

      1. ++array[s.charAt(i) - 'A'] 到底是做什么的?

        时间:2023-07-26
        <legend id='xPaDu'><style id='xPaDu'><dir id='xPaDu'><q id='xPaDu'></q></dir></style></legend>

      2. <i id='xPaDu'><tr id='xPaDu'><dt id='xPaDu'><q id='xPaDu'><span id='xPaDu'><b id='xPaDu'><form id='xPaDu'><ins id='xPaDu'></ins><ul id='xPaDu'></ul><sub id='xPaDu'></sub></form><legend id='xPaDu'></legend><bdo id='xPaDu'><pre id='xPaDu'><center id='xPaDu'></center></pre></bdo></b><th id='xPaDu'></th></span></q></dt></tr></i><div id='xPaDu'><tfoot id='xPaDu'></tfoot><dl id='xPaDu'><fieldset id='xPaDu'></fieldset></dl></div>

          <bdo id='xPaDu'></bdo><ul id='xPaDu'></ul>

            <tbody id='xPaDu'></tbody>

                  <small id='xPaDu'></small><noframes id='xPaDu'>

                  <tfoot id='xPaDu'></tfoot>
                  本文介绍了++array[s.charAt(i) - 'A'] 到底是做什么的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  for (int i = 0; i < s.length(); ++i) 
                      {
                          if (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z') 
                          {
                              ++array[s.charAt(i) - 'A'];
                          }
                      }
                  

                  我了解 For 循环.s.length() 是 26,确切地说是 int[26].所以这个循环会发生26次,0-25.如果 i, 0-25 处的字符介于 AZ 之间或为 AZ 它将继续执行 ++array[s.charAt(i) - 'A']; 从我看到的情况来看,它会添加一次数组每个循环,或者每次循环添加一次数组的值,对于 char i 处的字符串,所以第一个是 0 秒是 2,因为数组从 0 开始.所以在 i 的位置添加一个数组 -'A' 是我感到困惑的地方.

                  I understand the For loop. the s.length() is 26, int[26] to be exact. so this loop will occur 26 times, 0-25. If the Char at i, 0-25 is between or are A-Z it will then proceed to ++array[s.charAt(i) - 'A']; From what i see it adds array once per loop, or adds the value of array once per loop, for the String at char i so the first one would be 0 second would be 2, because arrays start at 0. so adding an array at location of i -'A' is where i get confused.

                  推荐答案

                  语句 ++array[s.charAt(i) - 'A']; 正在递增索引数组中的值通过 s.charAt(i) - 'A'.

                  The statement ++array[s.charAt(i) - 'A']; is incrementing the value in the array indexed by s.charAt(i) - 'A'.

                  这个循环的作用是计算 s 中每个字母出现的次数.

                  What this loop does is that it counts up the number of occurrences of each letter in s.

                  - 'A' 的原因是它移动"了 ascii/unicode 值,因此 A - Z 的值是 0 - 25.因此更适合作为数组索引.

                  The reason for - 'A', is that it "shifts" the ascii/unicode value so that A - Z have values 0 - 25. And are thus more suitable as an array index.

                  这篇关于++array[s.charAt(i) - 'A'] 到底是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为什么 System.out.println() 中的字符不增加? 下一篇:将单个字符转换为 CharSequence 的最有效方法

                  相关文章

                  最新文章

                  <small id='t9FX6'></small><noframes id='t9FX6'>

                    <i id='t9FX6'><tr id='t9FX6'><dt id='t9FX6'><q id='t9FX6'><span id='t9FX6'><b id='t9FX6'><form id='t9FX6'><ins id='t9FX6'></ins><ul id='t9FX6'></ul><sub id='t9FX6'></sub></form><legend id='t9FX6'></legend><bdo id='t9FX6'><pre id='t9FX6'><center id='t9FX6'></center></pre></bdo></b><th id='t9FX6'></th></span></q></dt></tr></i><div id='t9FX6'><tfoot id='t9FX6'></tfoot><dl id='t9FX6'><fieldset id='t9FX6'></fieldset></dl></div>
                        <bdo id='t9FX6'></bdo><ul id='t9FX6'></ul>
                      <legend id='t9FX6'><style id='t9FX6'><dir id='t9FX6'><q id='t9FX6'></q></dir></style></legend>
                    1. <tfoot id='t9FX6'></tfoot>