• <small id='lVZjj'></small><noframes id='lVZjj'>

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

    <tfoot id='lVZjj'></tfoot>
      <bdo id='lVZjj'></bdo><ul id='lVZjj'></ul>

  • <legend id='lVZjj'><style id='lVZjj'><dir id='lVZjj'><q id='lVZjj'></q></dir></style></legend>

      1. 用java中的char变量计算

        时间:2023-07-28

        <tfoot id='Gu3nm'></tfoot>

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

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

            • <small id='Gu3nm'></small><noframes id='Gu3nm'>

                  <tbody id='Gu3nm'></tbody>
                <legend id='Gu3nm'><style id='Gu3nm'><dir id='Gu3nm'><q id='Gu3nm'></q></dir></style></legend>
                • 本文介绍了用java中的char变量计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个学校作业,其中一项任务是解释许多微小的计算,并解释为什么 java 给你它给你的输出..

                  I have an assignment for school, and one of the tasks is to explain a lot of tiny calculations and explaining why java gives you the output it gives you..

                  其中一项计算是:

                  1 + '2' + 3

                  1 + '2' + 3

                  这对我来说是一个词汇错误,因为老师为我的系统使用了错误的撇号",但我已经和其他同学交谈过,他们告诉我他们得到了一个实际的输出,所以我开始阅读它,并发现它应该表示一个 char 变量,并且我还发现了系统特定类型,所以我更改了符号以适用于我的系统,现在我得到了答案 54..

                  which for me gives a lexical error, as the teacher used the wrong "apostrophes" for my system, but I've talked to other fellow students and they told me they got an actual output, so I started reading about it, and found out that it is supposed to signify a char variable, and I also found out about the system specific types, so I changed the signs to work for my system, and now I get the answer 54..

                  我看不到其中的逻辑,我尝试用 char 变量在 Google 上添加/计算/数学,但没有找到任何可以很好地解释它的东西..

                  and I cannot see the logic in it, and I've tried to google adding/calculating/math with char variables, and have found nothing that explains it well..

                  所以我求助于编码人员,有一天我可能会成为其中的一员,以帮助我理解其中的逻辑..

                  So I turn to you, the people of coding, that I one day might be a part of to help me understand the logic of this..

                  这开始是一个家庭作业,我可能只是回答它给出了一个词法错误,因为我的编译器不理解这个符号,但现在它已经达到了我的好奇心,我真的很想知道如何java设法得到这个答案..

                  this started out as a homework assignment that I probably could have gotten through by just answering that it gives a lexical error because my compiler doesn't understand the symbol, but now it's peaked my curiosity, and I really want to know how java manages to get this answer..

                  感谢您对此事的任何帮助!:)

                  thank you for any help on the matter! :)

                  我可以看到我无法制作作业"标签,所以我希望我可以把它放在这里:)

                  I can see that I couldn't make a 'homework' tag, so I hope it's okay that I put it here :)

                  推荐答案

                  在 Java 中,chars 可以通过 UTF-16 直接映射到 ints.但是,对于大多数常见字符,将 char 值转换为 int 会在 ascii 表中生成它的索引.+ 不是对字符的操作,而是对整数的操作.因此,java 采用 2 并在思考我无法添加这个"之后,意识到如果将其强制转换为 int,它可以添加它.

                  In Java, chars have a direct mapping to ints by UTF-16. For most common characters, though, casting a char value to an int yields its index on the ascii table. + isn't an operation on chars, but it is an operation for ints. Therefore, java is taking the 2 and after thinking "I can't add this", realizes it can add it if it casts it to an int.

                  正如您在表中看到的,2"的索引为 50,因此 1 + 50 + 3 = 54.

                  As you can see in the table, '2' has a index of 50, thus 1 + 50 + 3 = 54.

                  这篇关于用java中的char变量计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:字符串不能改变.但是int、char可以改变 下一篇:如何在 Java 中生成随机字符串

                  相关文章

                  最新文章

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

                  <tfoot id='N5jOL'></tfoot>

                • <small id='N5jOL'></small><noframes id='N5jOL'>

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