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

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

        Java中的递增字符类型

        时间:2023-07-28
          <tbody id='KCIgf'></tbody>
          <bdo id='KCIgf'></bdo><ul id='KCIgf'></ul>

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

          1. <legend id='KCIgf'><style id='KCIgf'><dir id='KCIgf'><q id='KCIgf'></q></dir></style></legend>

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

                  本文介绍了Java中的递增字符类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在练习 Java 时,我随机想到了这个:

                  While practicing Java I randomly came up with this:

                  class test
                  {
                      public static void main(String arg[])
                      {
                          char x='A';
                          x=x+1;
                          System.out.println(x);
                      }
                  }
                  

                  我以为它会抛出一个错误,因为我们不能将数值 1 与数学中的字母 A 相加,但是下面的程序运行正确并打印

                  I thought it will throw an error because we can't add the numeric value 1 to the letter A in mathematics, but the following program runs correctly and prints

                  B 
                  

                  这怎么可能?

                  推荐答案

                  在 Java 中,char 是数字类型.当您将 1 添加到 char 时,您将进入下一个 unicode 代码点.如果是 'A',下一个代码点是 'B':

                  In Java, char is a numeric type. When you add 1 to a char, you get to the next unicode code point. In case of 'A', the next code point is 'B':

                  char x='A';
                  x+=1;
                  System.out.println(x);
                  

                  请注意,您不能使用 x=x+1,因为它会导致隐式缩小转换.您需要改用 x++x+=1.

                  Note that you cannot use x=x+1 because it causes an implicit narrowing conversion. You need to use either x++ or x+=1 instead.

                  这篇关于Java中的递增字符类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:理解 Java 中 null 和 'u000' 的区别 下一篇:Java - 为什么 char 不应该被隐式转换为字节(和短

                  相关文章

                  最新文章

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

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

                    1. <tfoot id='REm8Y'></tfoot>
                    2. <legend id='REm8Y'><style id='REm8Y'><dir id='REm8Y'><q id='REm8Y'></q></dir></style></legend>