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

  • <tfoot id='SEzg8'></tfoot>
    <legend id='SEzg8'><style id='SEzg8'><dir id='SEzg8'><q id='SEzg8'></q></dir></style></legend>

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

        为什么 System.out.println() 中的字符不增加?

        时间:2023-07-26
          <bdo id='kPbuC'></bdo><ul id='kPbuC'></ul>
          <i id='kPbuC'><tr id='kPbuC'><dt id='kPbuC'><q id='kPbuC'><span id='kPbuC'><b id='kPbuC'><form id='kPbuC'><ins id='kPbuC'></ins><ul id='kPbuC'></ul><sub id='kPbuC'></sub></form><legend id='kPbuC'></legend><bdo id='kPbuC'><pre id='kPbuC'><center id='kPbuC'></center></pre></bdo></b><th id='kPbuC'></th></span></q></dt></tr></i><div id='kPbuC'><tfoot id='kPbuC'></tfoot><dl id='kPbuC'><fieldset id='kPbuC'></fieldset></dl></div>
            <tbody id='kPbuC'></tbody>

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

              <tfoot id='kPbuC'></tfoot>
            1. <small id='kPbuC'></small><noframes id='kPbuC'>

                • 本文介绍了为什么 System.out.println() 中的字符不增加?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  char char1 = 'a';   
                  System.out.println(char1);      //prints char 1
                  System.out.println(char1+1);    //prints char 1
                  System.out.println(char1++);     //prints char 1
                  System.out.println(char1+=1);    //prints incremented char1
                  char1 += 1;                     
                  System.out.println(char1);      //prints incremented char1
                  

                  在上面,为什么 (char1+1) 或 (char++) 不打印递增的字符而其他两个打印?

                  In the above, why doesn't (char1+1) or (char++) print the incremented character but theother two do?

                  推荐答案

                  首先,我假设因为您说 System.out.println 中的增量有效,所以您确实指定了:

                  First, I'm assuming that because you say the increment in System.out.println works, that you have really specified:

                  char char1 = 'a';
                  

                  编辑

                  针对问题的变化 (char1+1; => char1 += 1;) 我看到了问题.输出是

                  In response to the change of the question (char1+1; => char1 += 1;) I see the issue. The output is

                  a
                  98
                  b
                  

                  98 出现是因为 char a 被提升为 int(二进制数字提升)以加 1.所以 a 变为 97('a' 的 ASCII 值)和 98 个结果.

                  The 98 shows up because the char a was promoted to an int (binary numeric promotion) to add 1. So a becomes 97 (the ASCII value for 'a') and 98 results.

                  但是,char1 += 1;char1++ 不执行二进制数字提升,因此可以按预期工作.

                  However, char1 += 1; or char1++ doesn't perform binary numeric promotion, so it works as expected.

                  引用 JLS,第 5.6.2 节,二进制数字提升":

                  加宽基元转换(第 5.1.2 节)用于转换或两个操作数均由以下规则指定:

                  Widening primitive conversion (§5.1.2) is applied to convert either or both operands as specified by the following rules:

                  如果任一操作数是 double 类型,则另一个将转换为 double.

                  If either operand is of type double, the other is converted to double.

                  否则,如果任一操作数为浮点类型,则转换另一个浮动.

                  Otherwise, if either operand is of type float, the other is converted to float.

                  否则,如果任一操作数是 long 类型,则转换另一个长.

                  Otherwise, if either operand is of type long, the other is converted to long.

                  否则,两个操作数都转换为 int 类型.

                  (强调我的)

                  这篇关于为什么 System.out.println() 中的字符不增加?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:你如何比较java中的字符? 下一篇:++array[s.charAt(i) - 'A'] 到底是做什么的?

                  相关文章

                  最新文章

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

                  <legend id='Sqgep'><style id='Sqgep'><dir id='Sqgep'><q id='Sqgep'></q></dir></style></legend>
                  • <bdo id='Sqgep'></bdo><ul id='Sqgep'></ul>

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

                  <tfoot id='Sqgep'></tfoot>