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

    <tfoot id='wUzp1'></tfoot>

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

        <bdo id='wUzp1'></bdo><ul id='wUzp1'></ul>
      <legend id='wUzp1'><style id='wUzp1'><dir id='wUzp1'><q id='wUzp1'></q></dir></style></legend>
    2. 在java中将两个整数除以一个double

      时间:2023-09-30

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

            <tbody id='wQNJr'></tbody>

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

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

                <bdo id='wQNJr'></bdo><ul id='wQNJr'></ul>
              • 本文介绍了在java中将两个整数除以一个double的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我可以看到这是新程序员的常见问题,但是我没有成功地为我的代码实现任何解决方案.基本上我想将 w 和 v 相除,它们必须保存到一个双变量中.但它打印 [0.0, 0.0, ... , 0.0]

                I can see this is a common problem for new programmers, however I didn't succeed in implementing any of the solution to my code. Basically I want to divide w and v, which must be saved to a double variable. But it prints [0.0, 0.0, ... , 0.0]

                public static double density(int[] w, int[] v){
                double d = 0;
                    for(L = 0; L < w.length; L++){
                        d = w[L]  /v[L];
                    }
                    return d;
                }
                

                推荐答案

                这里的这一行 d = w[L]/v[L]; 发生在几个步骤中

                This line here d = w[L] /v[L]; takes place over several steps

                d = (int)w[L]  / (int)v[L]
                d=(int)(w[L]/v[L])            //the integer result is calculated
                d=(double)(int)(w[L]/v[L])    //the integer result is cast to double
                

                换句话说,在你转换成双精度之前,精度已经消失了,你需要先转换成双精度,所以

                In other words the precision is already gone before you cast to double, you need to cast to double first, so

                d = ((double)w[L])  / (int)v[L];
                

                这会强制 java 在整个过程中使用双精度数学,而不是使用整数数学,然后在最后强制转换为双精度

                This forces java to use double maths the whole way through rather than use integer maths and then cast to double at the end

                这篇关于在java中将两个整数除以一个double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何从 Java 中的十进制整数中获取十六进制值? 下一篇:使用 nextInt 和 nextLine() 时遇到问题

                相关文章

                最新文章

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

              • <tfoot id='5p9zY'></tfoot>

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

                  2. <small id='5p9zY'></small><noframes id='5p9zY'>