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

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

        <tfoot id='eGyVH'></tfoot>

        <i id='eGyVH'><tr id='eGyVH'><dt id='eGyVH'><q id='eGyVH'><span id='eGyVH'><b id='eGyVH'><form id='eGyVH'><ins id='eGyVH'></ins><ul id='eGyVH'></ul><sub id='eGyVH'></sub></form><legend id='eGyVH'></legend><bdo id='eGyVH'><pre id='eGyVH'><center id='eGyVH'></center></pre></bdo></b><th id='eGyVH'></th></span></q></dt></tr></i><div id='eGyVH'><tfoot id='eGyVH'></tfoot><dl id='eGyVH'><fieldset id='eGyVH'></fieldset></dl></div>
      1. 如何获得整数的单独数字?

        时间:2023-10-01

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

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

        • <tfoot id='eXz71'></tfoot>

                <tbody id='eXz71'></tbody>

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

                1. <legend id='eXz71'><style id='eXz71'><dir id='eXz71'><q id='eXz71'></q></dir></style></legend>
                  本文介绍了如何获得整数的单独数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有 1100、1002、1022 等数字.我想要单独的数字,例如对于第一个数字 1100,我想要 1、1、0、0.

                  I have numbers like 1100, 1002, 1022 etc. I would like to have the individual digits, for example for the first number 1100 I want to have 1, 1, 0, 0.

                  如何在 Java 中获得它?

                  How can I get it in Java?

                  推荐答案

                  为此,您将使用 % (mod) 运算符.

                  To do this, you will use the % (mod) operator.

                  int number; // = some int
                  
                  while (number > 0) {
                      print( number % 10);
                      number = number / 10;
                  }
                  

                  mod 运算符将为您提供对数字进行 int 除法的余数.

                  The mod operator will give you the remainder of doing int division on a number.

                  所以,

                  10012 % 10 = 2
                  

                  因为:

                  10012 / 10 = 1001, remainder 2
                  

                  注意: 正如 Paul 所说,这会以相反的顺序为您提供数字.您需要将它们压入堆栈并以相反的顺序将它们弹出.

                  Note: As Paul noted, this will give you the numbers in reverse order. You will need to push them onto a stack and pop them off in reverse order.

                  按正确顺序打印数字的代码:

                  Code to print the numbers in the correct order:

                  int number; // = and int
                  LinkedList<Integer> stack = new LinkedList<Integer>();
                  while (number > 0) {
                      stack.push( number % 10 );
                      number = number / 10;
                  }
                  
                  while (!stack.isEmpty()) {
                      print(stack.pop());
                  }
                  

                  这篇关于如何获得整数的单独数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Java中的大数 下一篇:检查字符串是否代表Java中的整数的最佳方法是什

                  相关文章

                  最新文章

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

                  1. <small id='PUFeC'></small><noframes id='PUFeC'>

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

                    2. <tfoot id='PUFeC'></tfoot>

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