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

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

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

        为什么我可以将字符添加到字符串但不能将字符

        时间:2023-07-26

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

            <tbody id='d4C9A'></tbody>

            <bdo id='d4C9A'></bdo><ul id='d4C9A'></ul>
            1. <tfoot id='d4C9A'></tfoot>
              <i id='d4C9A'><tr id='d4C9A'><dt id='d4C9A'><q id='d4C9A'><span id='d4C9A'><b id='d4C9A'><form id='d4C9A'><ins id='d4C9A'></ins><ul id='d4C9A'></ul><sub id='d4C9A'></sub></form><legend id='d4C9A'></legend><bdo id='d4C9A'><pre id='d4C9A'><center id='d4C9A'></center></pre></bdo></b><th id='d4C9A'></th></span></q></dt></tr></i><div id='d4C9A'><tfoot id='d4C9A'></tfoot><dl id='d4C9A'><fieldset id='d4C9A'></fieldset></dl></div>
                <legend id='d4C9A'><style id='d4C9A'><dir id='d4C9A'><q id='d4C9A'></q></dir></style></legend>
                • 本文介绍了为什么我可以将字符添加到字符串但不能将字符添加到字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  所以我想将一个字符添加到一个字符串中,并且在某些情况下想要将该字符加倍然后将其添加到一个字符串中(即先添加到它本身).我试过了,如下所示.

                  So I wanted to add a character to a string, and in some cases wanted to double that characters then add it to a string (i.e. add to it itself first). I tried this as shown below.

                  char s = 'X'; 
                  String string = s + s;
                  

                  这引发了一个错误,但我已经在字符串中添加了一个字符,所以我尝试了:

                  This threw up an error, but I'd already added a single character to a string so I tried:

                  String string = "" + s + s;
                  

                  哪个有效.为什么在总和中包含一个字符串会导致它起作用?是否添加了一个字符串属性,由于字符串的存在,该属性只能由字符转换为字符串时使用?

                  Which worked. Why does the inclusion of a string in the summation cause it to work? Is adding a string property which can only be used by characters when they're converted to strings due to the presence of a string?

                  推荐答案

                  因为String + Char = String,类似于int + double = double.

                  It's because String + Char = String, similar to how an int + double = double.

                  尽管其他答案告诉你什么,Char + Char 是 int.

                  Char + Char is int despite what the other answers tell you.

                  字符串 s = 1;//由于类型不匹配导致的编译错误.

                  String s = 1; // compilation error due to mismatched types.

                  您的工作代码是 (String+Char)+Char.如果你这样做了: String+(Char+Char) 你会在你的字符串中得到一个数字.示例:

                  Your working code is (String+Char)+Char. If you had done this: String+(Char+Char) you would get a number in your string. Example:

                  System.out.println("" + ('x' + 'x')); // prints 240
                  System.out.println(("" + 'x') + 'x'); // prints xx - this is the same as leaving out the ( ).
                  

                  这篇关于为什么我可以将字符添加到字符串但不能将字符添加到字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:char 对象对应于哪个字符编码(Unicode 版本)集? 下一篇:用某种方法在java中的字符串中选择一个随机字符

                  相关文章

                  最新文章

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

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

                    <bdo id='rLedJ'></bdo><ul id='rLedJ'></ul>
                  <tfoot id='rLedJ'></tfoot>
                  <legend id='rLedJ'><style id='rLedJ'><dir id='rLedJ'><q id='rLedJ'></q></dir></style></legend>